If I understand you correctly, you have an NSArray
(you didn't say of what, so I'll assume NSDictionary
) of Atom feed items, each of which has a category. What you want is a structure that groups the items by category into NSArray
s.
The appropriate data structure, in my opinion, is an NSDictionary
that maps categories onto arrays of items. Here's how I would do it:
NSMutableDictionary *itemsByCategory = [NSMutableDictionary dictionary];
for (NSDictionary *item in allItems) {
NSString *category = [item objectForKey:@"category"];
NSMutableArray *categoryItems = [itemsByCategory objectForKey:category]; // You'll probably want to do some checking in case there is no category.
if (!categoryItems) {
categoryItems = [NSMutableArray array];
[itemsByCategory setObject:categoryItems forKey:category];
}
[categoryItems addObject:item];
}