I’ve been using the following to create an array from a plist of dictionaries:
self.cough = [NSMutableArray arrayWithCapacity:[ailments count]];
NSDictionary* dict;
for (dict in ailments)
if ([[dict valueForKey:@"section"]isEqualToString:@"coughing"])[cough addObject:dict];
The format of the plist is:
section: coughing
name: Common Cold
The trouble I’m having, and I suspect its an easy one is, if I want to have “Common Cold” in a different section, like “Headache”, I could create another ailment object for the new section but it messes up my search result by showing 2 Common Cold entries (from both “Coughing” and “Headache”).
What I’d like to do is:
section: coughing, headache
name: Common Cold
What would I use instead of isEqualToString: to create two different arrays, one for “Coughing” and another for “Headache”?
It appears that you are manually checking against for section type. If you wanted to continue this way, all you really need to do is check and see if the section string contains the substring of the particular section you’re evaluating for:
How do I check if a string contains another string in Objective-C?
However rather than statically define what section names you’re looking for, it might benefit you to consider trying to obtain sections names/types dynamically from your plist and then sorting into those sections.