Reputation: 65
i really don't know how to ask this since it was really painful to come up with a question title but i hope you will be able to help me
I got a plist.
i read it into an nsarray
NSArray *arrayOfPlist = [[NSArray alloc] initWithContentsOfFile:path];
this pList is in this format.
<array>
<dict>
<key>category</key>
<string>desert</string>
<key>numberOfPerson</key>
<string>3</string>
<key>recipeImage</key>
<string>asdasd.jpg</string>
<key>time</key>
<string>15</string>
<key>recipeName</key>
<string>asd asdad</string>
<key>recipeDetail</key>
<string>asdasd</string>
<key>recipeIngredients</key>
User enters inputs into a textField.
where i store it as searchText
and i use NSPredicate to see if RecipeIngredients contains it.
At this point i m having troubles
When i try to use this array
NSArray* haves = [recipeIngredientsOfOneRecipeString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]];
it gives me this error [<__NSCFString 0x109291950> valueForUndefinedKey:]: this class is not key value coding-compliant for the key recipeIngredients.'
And the other thing is i can not imagine a proper way to check all recipeIngredients with given input.
I tried adding a bool predicate each time it returns true i incremented and when its count became same as haves.count i added it but this doesn't work either.
i am killing myself for a way to solve these problems and i m out of of ideas.
need a new perspective.
Upvotes: 0
Views: 110
Reputation: 3908
You can enumerate whole plist file to match the user input using the below code
NSArray* arrOfPlist = [[NSArray alloc] initWithContentsOfFile:path];
NSString* strMatch;//user Input
for (NSDictionary* dict in arrOfPlist)
{
for (id key in dict)
{
if ([[dict objectForKey:key]isEqualToString:strMatch])
{
//user search matches do whatever code you want here
break;
}
}
}
Upvotes: 1