将所有 plist 数组放入一个数组的有效方法?

发布于 2024-09-05 11:07:00 字数 811 浏览 3 评论 0原文

如果我有一个结构如下的 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 中的最有效方法是什么?

If I have a plist which is structured like this:

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

Then what is the most efficient way of getting all the names of the people into one big NSArray?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若言繁花未落 2024-09-12 11:07:00

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

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

正常方法:

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

The shortest but probably very inefficient way:

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

the normal way:

NSMutableArray* resArr = [NSMutableArray array];
for (NSDictionary* record in thePlistArray) {
   [resArr addObjectsFromArray:[record objectForKey:@"People"]];
}
return resArr;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文