NSDictionry

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 )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 )aKey;

@end

2 简写

NSDictionary *dic = @{@"value1":@"key1",@"value2":@"key2"};

3 枚举不可放字典中

你可能感兴趣的:(NSDictionry)