Sprite Kit iOS7 - SKNode UserData property not storing values

后端 未结 1 1973
天命终不由人
天命终不由人 2021-01-12 08:21

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

[self.testSprit         


        
相关标签:
1条回答
  • 2021-01-12 09:15

    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]);
    
    0 讨论(0)
提交回复
热议问题