Reputation: 2535
I have a problem with NSPredicate. Can't think of a way of how to write it and can't find nothing similar. I have this predicate:
[NSPredicate predicateWithFormat:@"followedBy.username like %@", username];
And this returns all users that follows given user. I want to expand this predicate that it would also return user with ids' in the NSSet.
UserIDSetExample = @"1, 15, 14, 17, ..."
So in the end I would like that this predicate returned following user plus users with ids' from the set.
Any guidance or help would be greatly appreciated!!! Thanks in advance!
Upvotes: 0
Views: 161
Reputation: 7704
Your predicate should look like this:
[NSPredicate predicateWithFormat:@"followedBy.id in %@ OR followedBy.username like %@", idsSet, username];
Matching by ID should be first condition in the OR
because searching if the ID (number) is in the set will likely be faster than string compares for the username
Upvotes: 2
Reputation: 5226
It can be array, set, or dictionary (as pointed out by @MikePollard) and you can use the following pattern for your predicate:
[NSPredicate predicateWithFormat:@"id IN %@", idArray]
Upvotes: 1