【发布时间】:2020-11-03 16:15:34
【问题描述】:
我正在学习 Objective-c。
我试图通过使用数字作为键来获取这个NSMutableDictionary 的条目:
// [game analysisData] returns the Dictionary
NSMutableDictionary *data = [game analysisData];
NSLog(@"Data:\n%@", data);
// Try using "1" as the key.
id move = [data objectForKey:"1"];
NSLog(@"Move:\n%@", move);
但是输出不好:
move == (null).
所以我无法使用字符串"1" 访问它。使用 int 不起作用(编译错误)。
你知道我如何访问这个 NSMutableDictionary 的条目吗?
【问题讨论】:
-
似乎是
NSNumber,但是有什么:for (id aKey in [data allKeys]) { NSLog(@"Key %@ is of class %@", aKey, NSStringFromClass([aKey class])); }来检查:)