https://blog.csdn.net/itianyi/article/details/8661997
1.setValue和setObject的区别
1>使用
1.2者都是为可变字典赋值
- (void)setValue:(id)value forKey:(NSString *)key;
- (void)setObject:(id)anObject forKey:(id <NSCopying>)aKey;
2.区别
setValue不仅仅是对字典使用,对任何对象都可以;
key对应的只能是字符串;
当value为空时,会调用removeObject删除;
setObject:是字典特有的方法
key不仅仅是字符串,是id类型
@interface NSMutableDictionary(NSKeyValueCoding)
/* Send -setObject:forKey: to the receiver, unless the value is nil, in which case send -removeObject:forKey:.
*/
- (void)setValue:(id)value forKey:(NSString *)key;
@end
@interface NSMutableDictionary :NSDictionary
- (void)removeObjectForKey:(id)aKey;
- (void)setObject:(id)anObject forKey:(id <NSCopying>)aKey;
@end
2 简写
NSDictionary *dic = @{@"value1":@"key1",@"value2":@"key2"};
网友评论