Passing NSInteger variable to NSMutableDictionary or NSMutableArray

后端 未结 7 924
北恋
北恋 2020-12-28 12:42

Why does this not work:

NSInteger temp = 20;
[userSettingsFromFile setObject:temp forKey:@\"aTemp\"];

but this does:

[userS         


        
7条回答
  •  萌比男神i
    2020-12-28 12:52

    Whatever you pass through setObject has to be derived from NSObject. NSInteger is not, it's a simple int typedef. In your 2nd example you use NSString, which is derived from NSObject.

提交回复
热议问题