zoukankan      html  css  js  c++  java
  • NSDictionary NSMutableDictionary 常用方法

    构造方法
         [[NSDictionary alloc] initWithObjectsAndKeys:(nonnull id), ..., nil]
         [[NSDictionary alloc] initWithObjects:(nonnull NSArray *) forKeys:(nonnull NSArray<id<NSCopying>> *)]
         
    类工厂方法
         [NSDictionary dictionaryWithObjectsAndKeys:(nonnull id), ..., nil];
         [NSDictionary dictionaryWithObjects:(const id  _Nonnull __unsafe_unretained *) forKeys:(const id<NSCopying>  _Nonnull __unsafe_unretained *) count:(NSUInteger)];
     
    快速创建
    NSDictionary *dict = @{@"key1": @“value1",
                           @"key2": @“value2",
                           @"key3": @“value3",
                                . . .                         
                                              };
     
     
    遍历
        NSArray *keys = [dict allKeys];(查找所有 key值,并放入一个数组中)
        NSArray *values = [dict allValues];
    forin
    迭代器
     
    writeToFile: atomically: 从文件中读取
    dictionaryWithContentsOfFile:  也可以写入文件中
     
     

     
    NSMutableDictionary *dictM = [[NSMutableDictionary alloc] init];
     
    NSMutableDictionary添加和修改内容使用的是同一个方法
         [dictM setObject:@"keyAdd" forKey:@"valueAdd"];     
         dictM[@"keyAdd"] = @“valueAdd”;(推荐)
     
    删除
         [dictM removeObjectForKey:@"keyDelete"];
         dictM[@“keyDelete"] = nil;
     
    查询
         dictM[@“keyLookFor”];
  • 相关阅读:
    NTDDI_VERSION,_WIN32_WINNT,WINVER,_WIN32_IE
    SOL_SOCKET, SO_KEEPALIVE
    荣幸的一天
    值得思考的一些东西
    一个flash前后台开源框架的的站点
    30个AS3开源项目
    [算法] doj 1066 最长上升子序列
    [算法] doj 1605 Common Subsequence 公共子序列
    华为EC321CDMA PCMICA 无线网卡Ubuntu下使用
    my_judged.cc 的初稿
  • 原文地址:https://www.cnblogs.com/fangweiyi/p/5299630.html
Copyright © 2011-2022 走看看