注: 本文暂时只描述在NSMutableDictionary的实例对象中使用 这两个api的区别
setValue:forKey:
/* Send -setObject:forKey: to the receiver, unless the value is nil, in which case send -removeObjectForKey:.*/
- (void)setValue:(nullable ObjectType)value forKey:(NSString *)key;
这个API的key是 字符串类型的。value可以是任意对象类型。如果value的值传入了nil,则会调用-removeObjectForKey:,会移除这个key。
setObject: forKey:
- (void)setObject:(ObjectType)anObject forKey:(KeyType)aKey;
这个API的key可以是任意对象类型的。但是value不能是nil。如果是nil这抛出异常。
事实上 setObject是Dictionary的Api,setValue 是Object的Api。