iOS基础:NSDictionary常用方法

来源:互联网 发布:免费域名注册永久 编辑:程序博客网 时间:2024/06/05 02:33

一、NSDictionary常用方法

//创建

NSDictionary * dict2 =@{@"1":@"dog1",@"2":@"dog2",@"3":@"dog3"};

+ (instancetype)dictionaryWithObjectsAndKeys:(id)firstObject, ... NS_REQUIRES_NIL_TERMINATIONNS_SWIFT_UNAVAILABLE("Use dictionary literals instead");

+ (instancetype)dictionaryWithDictionary:(NSDictionary<KeyType, ObjectType> *)dict;

//操作

NSUInteger count = [dict2count];

- (nullable ObjectType)objectForKey:(KeyType)aKey;


二、NSMutableDictionary常用方法

//添加

- (void)setObject:(id)anObject forKey:(id <NSCopying>)aKey;

//删除指定key的对象

- (void)removeObjectForKey:(id)aKey;

//删除所有的对象

- (void)removeAllObjects;



0 0