문제

I would think this work work easily, however I cannot understand why my NSMutableDictionary property is not working as I would have expected.

[self.testSprite.userData setValue:@"CAT" forKey:@"key"];
NSLog(@"%@", [self.testSprite.userData objectForKey:@"key"]);
NSLog(@"%lu", [self.testSprite.userData count]);

I am retuning (null) and 0.

Is there a special trick for using the spriteNode userdata ?

Thanks

도움이 되었습니까?

해결책

The userData property is initially nil. You have to create a dictionary and assign it first:

self.testSprite.userData = [NSMutableDictionary dictionary];

[self.testSprite.userData setValue:@"CAT" forKey:@"key"];
NSLog(@"%@", [self.testSprite.userData objectForKey:@"key"]);
NSLog(@"%lu", [self.testSprite.userData count]);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top