Reputation: 588
I am attempting to filter an Array of dictionary objects using NSPredicate
. I have an array of Ids that I want to filter this array against however I'm not sure on how to do so. This is the closest I have got to a working version. However NSPredicate
is thinking that Self.id is a number when it is a NSString
Guide
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"SELF.id CONTAINS %@", UserIds];
However this errors out with the following:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't look for value ((
"36eaec5a-00e7-4b10-b78e-46f7396a911b",
"26fc5ea2-a14b-4535-94e9-6fb3d113838c",
"0758a7d0-0470-4ff6-a96a-a685526bccbb",
"10dae681-a444-469c-840d-0f16a7fb0871",
"0280234c-36ae-4d5f-994f-d6ed9eff6b62",
"89F1D9D4-09E2-41D3-A961-88C49313CFB4"
)) in string (1f485409-9fca-4f2e-8ed2-f54914e6702a); value is not a string '
Any help you can provide would be great.
Upvotes: 1
Views: 1739
Reputation: 1106
You are going to want to use IN
to compare the value of SELF.id
to array values, instead of CONTAINS
, which performs string matching.
Solution:
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"SELF.id IN %@", UserIds];
Upvotes: 6