iPhone - 合并 NSArray 中的键 (Objective-C)

发布于 2024-08-29 16:28:54 字数 333 浏览 2 评论 0原文

我在数组和键方面遇到了麻烦...我的数据库中有一个数组:

NSArray *elementArray = [[[menuArray valueForKey:@"meals"] valueForKey:@"recipe"] valueForKey:@"elements"]

这里的问题是我希望将我所有菜单的所有餐食的所有元素都放在一个数组中,这样: [elementArray objectAtIndex:0] = 我的第一个元素 等等... 在上面的示例中,元素由键分隔。 我怎样才能得到它?

希望它足够清楚......

谢谢

I'm having troubles with arrays and keys... I have an array from my database:

NSArray *elementArray = [[[menuArray valueForKey:@"meals"] valueForKey:@"recipe"] valueForKey:@"elements"]

The problem here is that I would like all my elements of all my meals of all my menus in an array such that:
[elementArray objectAtIndex:0] = my first element
etc...

In the example above, the elements are separated by the keys.
How can I get that?

Hope it's clear enough...

Thanks

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

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

发布评论

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

评论(1

盗梦空间 2024-09-05 16:28:54

从您的代码片段来看,我不清楚您的数据的结构,但我认为它类似于拥有 NSArray 的 NSDictionary (称为 aDictionary 并希望将所有 NSArray 合并为一个。如果是这种情况,那么:(

NSMutableArray *resultArray = [[[NSMutableArray alloc] init] autorelease];
for (id dictionaryKey in aDictionary) {
    [resultArray addObjectsFromArray:[aDictionary objectForKey:dictionaryKey]];
}
return [NSArray arrayWithArray:resultArray];

此代码尚未经过测试。)

From your code snippet, it is not clear to me exactly how your data is structured, but I think it's analogous to having an NSDictionary (called aDictionary) of NSArray and wanting to combine all the NSArray into one. If this is the case, then:

NSMutableArray *resultArray = [[[NSMutableArray alloc] init] autorelease];
for (id dictionaryKey in aDictionary) {
    [resultArray addObjectsFromArray:[aDictionary objectForKey:dictionaryKey]];
}
return [NSArray arrayWithArray:resultArray];

(This code has not been tested.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文