字典的创建方法:
用简写形式定义一个字典
NSDictionary *dict = @{@"zbz":@"zhangbozhi",@"xzmly":@"hello"};
获取key对应的值:dict[@"zbz"]
+ (id)dictionaryWithObjectsAndKeys:(id)firstObject, ...;
+ (id)dictionaryWithDictionary:(NSDictionary *)dict;
- (id)initWithObjectsAndKeys:(id)firstObject, ...;
- (id)initWithDictionary:(NSDictionary *)otherDictionary;
字典的常用方法:
- (NSUInteger)count;
- (id)objectForKey:(id)aKey;
- (NSArray *)allKeysForObject:(id)anObject;//找到所有的值相同的键
- (NSArray *)allKeys;
- (NSArray *)allValues;
字典的元素的添加:
- (void)addEntriesFromDictionary:(NSDictionary *)otherDictionary;
- (void)setObject:(id)anObject forKey:(id <NSCopying>)aKey;
删除字典的元素:
- (void)removeAllObjects;
- (void)removeObjectsForKeys:(NSArray *)keyArray;
- (void)removeObjectForKey:(id)aKey;
重置可变字典
- (void)setDictionary:(NSDictionary *)otherDictionary;
网友评论