iOS基础:NSDictionary常用方法

一、NSDictionary常用方法

//创建

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

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

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

//操作

NSUInteger count = [dict2 count];

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


二、NSMutableDictionary常用方法

//添加

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

//删除指定key的对象

- (void)removeObjectForKey:(id)aKey;

//删除所有的对象

- (void)removeAllObjects;



你可能感兴趣的:(ios)