user3626615
user3626615

Reputation: 17

How to use NSPredicate with Multidimensional array (where the predicateFormat exists at valueForKeyPath)

I have an array where the 'id' on which i want to filter the array exists at valueForKeyPath 'objectId' of each of its dictionaries. How to compare the predicates in ValueForKeyPath.

Currently.. this predicate

NSPredicate * objIdPredicate = [NSPredicate predicateWithFormat:@"objectId = %@",obj];
NSArray * oneOrder = [array filteredArrayUsingPredicate:objIdPredicate];

is considering key and values of the array elements, not the ones at their ValueForKeyPath=@"objectId"

Upvotes: 0

Views: 515

Answers (1)

UIBittu
UIBittu

Reputation: 215

Use "self"in your code to get the array element's valueForKeyPath

NSPredicate *objIdPredicate =[NSPredicate predicateWithFormat:@"(self.objectId = %@)",obj];

`

Upvotes: 2

Related Questions