NSMutableDictionary中 setValue和setObject的区别

对于- (void)setValue:(id)value forKey:(NSString *)key;函数 官方解释如下

Send -setObject:forKey: to the receiver, unless the value is nil, in which case send -removeObject:forKey:

这就很明确的说明了setValue:forKey:中value能够为nil,但是当value为nil的时候,会自动调用removeObject:forKey方法,通过测试可以得知调用 setObject:forkey:函数时object是不能够为nil的。否则会崩溃

另外通过函数的定义可知 

setValue:forKey:中key只能够是NSString类型,而setObject:forKey:的可以是任何类型

原文地址:https://www.cnblogs.com/lidaojian/p/4482543.html