【问题标题】:Efficient method of getting all plist arrays into one array?将所有 plist 数组放入一个数组的有效方法?
【发布时间】:2010-06-08 09:36:53
【问题描述】:

如果我有一个结构如下的 plist:

Root              Array
   Item 0         Dictionary
     City         String     New York
     People       Array
        Item 0    String     Steve
        Item 1    String     Paul
        Item 2    String     Fabio
        Item 3    String     David
        Item 4    String     Penny
   Item 1         Dictionary
     City         String     London
     People       Array
        Item 0    String     Linda
        Item 1    String     Rachel
        Item 2    String     Jessica
        Item 3    String     Lou
   Item 2         Dictionary
     City         String     Barcelona
     People       Array
        Item 0    String     Edward
        Item 1    String     Juan
        Item 2    String     Maria

那么将所有人的姓名放入一个大的 NSArray 中最有效的方法是什么?

【问题讨论】:

    标签: iphone objective-c nsarray plist


    【解决方案1】:

    最短但可能非常低效的方法:

    return [thePlistArray valueForKeyPath:@"@distinctUnionOfArrays.People"];
    

    正常方式:

    NSMutableArray* resArr = [NSMutableArray array];
    for (NSDictionary* record in thePlistArray) {
       [resArr addObjectsFromArray:[record objectForKey:@"People"]];
    }
    return resArr;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-24
      • 1970-01-01
      • 2012-01-18
      • 2022-01-26
      • 2012-07-01
      • 1970-01-01
      • 2020-11-19
      • 2017-07-20
      相关资源
      最近更新 更多