Reputation: 4350
Is there a way to filter or query data in a plist. For example I want all objects that has Type='People'
Upvotes: 2
Views: 616
Reputation: 16719
You can load the plist into dictionary and then get all values you want:
NSDictionary* dict = [NSDictionary dictionaryWithContentsOfFile: @"someplist.plist"];
Upvotes: 1
Reputation: 38032
If you load your PList into an NSArray you can use filteredArrayUsingPredicate:
along with an NSPredicate
to perform filtering. For example:
NSBundle* bundle = [NSBundle mainBundle];
NSString* path = [bundle pathForResource:@"data" ofType:@"plist"];
NSArray *array = [NSArray arrayWithContentsOfFile:...];
NSString *type = @"People";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Type == %@", type];
[array filteredArrayUsingPredicate:predicate];
Upvotes: 3