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 <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"};

3 枚举不可放字典中

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容