Reputation: 5495
Presently, I have a Game
class table with an attribute named currentTurnPlayer
. For a query, I am interested in getting all the game
objects where currentTurnPlayer
's name does not equal to my self.currentUser.username
In other words, I am stuck on trying to do the opposite of what default Parse' query method whereKey:containsString:
does, and to only retrieve objects where the key does not contain the string self.currentUser.username
. How would I be able to accomplish this? Thanks!
Upvotes: 0
Views: 914
Reputation: 3181
I would suggest using PFQuery with your own predicate.
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"currentTurnPlayer != %@",
self.currentUser.username];
PFQuery *query = [PFQuery queryWithClassName:[Game parseClassName]
predicate:predicate];
... and then execute the query as usual.
Parse doesn't support all predicate statements, but it supports the basic ones, including ==
and !=
.
Upvotes: 2
Reputation: 5088
Using whereKey:notEqualTo:
should do the trick. However if you're not matching exact name to exact name (i.e. allowing the user to enter a search term), that obviously won't work.
In that case you'll want to use whereKey:matchesRegex:
I'm not a regex pro but here's an example.
[query whereKey:@"currentTurnPlayer" matchesRegex:[NSString stringWithFormat:@"(?i:^.*%@.*$)", playerName]];
Upvotes: 2