NSMutableDictionary setObjetct forKey id NSString

Her*_*ker 2 cocoa objective-c ios

坦率地说,这是一个非常详细的问题.NSMutableDictionary的苹果文档https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/Reference/Reference.html声明:

setObject:forKey:
Adds a given key-value pair to the dictionary.
- (void)setObject:(id)anObject forKey:(id)aKey
Run Code Online (Sandbox Code Playgroud)

根据该参数forKey接受任何对象.但是,当我尝试传递一个NSNumber时,Incompatible pointer types sending 'NSNumber *' to parameter of type 'NSString *' 只有一些NSString被接受为关键.

在我想要的时候,我会将我的号码转换为字符串.最后它只是一把钥匙.但有谁知道谁是对的?文档或编译器?

mip*_*adi 11

不应该使用的时候拿到的警告setObject:forKey:.但是,在使用类似命名时,您收到警告setValue:forKey:.后者虽然名称相似,但它是键值编码系统的一部分,因此只接受一个NSString键作为关键.

这是一个展示差异的示例程序.