Reputation: 459
How to filter an array of dictionaries with NSPredicate
based on key
of a dictionary inside another dictionary(which is inside an array), here is my response.
[
{
"_id" = {
"$id" = 53e28497e37c70d83021c830;
};
access = public;
},
{
"_id" = {
"$id" = 53e28497e37c70d83021c839;
};
access = public;
}
]
Now I need to filter this array based on the key $id
. I tried different predicate formats to filter this array but no luck.How can I get dictionary object which matches $id
.
Upvotes: 1
Views: 901
Reputation: 8460
try like this,
NSArray *filtered = [array filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self.id.%K == '1'",@"$id"]];
Upvotes: 1
Reputation: 3658
NSString* filter = @"53e28497e37c70d83021c839";
NSArray* res = [originArray filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"%K LIKE[c] %@", @"_id.$id", filter]];
Upvotes: 0