문제

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?

도움이 되었습니까?

해결책

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];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top