Question

I got a p list with

root - array
  Item 0 - dictionary
    locationName - string
    rating - number
    reason - string
  Item 1
  ....

So i got a NSString with the input text and i want to search through my plist to check if the inputText is exist in my plist.

All i need to check in plist is locationName.

I tried to take my plist into a NSDictionary but i didn't know how to do continue

Do i need a loop like this

for(int k=0;k<= plist.length;k++;)

or is there any other way to go?

Was it helpful?

Solution

Use NSPredicate with format of SELF.locationName = 'some location' on an array of the elements:

NSPredicate * p = [NSPredicate predicateWithFormat:@"SELF.locationName = %@", @"My Location"];
NSArray * filteredArray = [yourArray filteredArrayUsingPredicate:p];

NSDictionary * firstElement = filteredArray[0];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top