美文网首页
Foundation - NSDictionary字典

Foundation - NSDictionary字典

作者: baiwulong | 来源:发表于2017-12-14 16:42 被阅读12次

    字典的创建方法:

    用简写形式定义一个字典

    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;
    

    相关文章

      网友评论

          本文标题:Foundation - NSDictionary字典

          本文链接:https://www.haomeiwen.com/subject/hiahwxtx.html