t0a0
t0a0

Reputation: 688

Parse.com How to know if an array does not contain an object

there is a method for PFQuery

PFQuery *query = [PFQuery queryWithClassName:@"class"];
[query whereKey:(NSString *)key containsAllObjectsInArray:(NSArray *)array];

is there similar method to define if there is NO specified object in array? like

[query whereKey:(NSString *)key doesNotContainAllObjectsInArray:(NSArray *)array];

If no, how to code this method by myself?

Upvotes: 6

Views: 3009

Answers (3)

Alex Wally
Alex Wally

Reputation: 2339

If you want to find objects where an Array key does not contain another object, you can simply use notEqualTo: as confirmed by a Parse developer here:

https://www.parse.com/questions/pfquery-not-include-any-object-in-array

Upvotes: 0

Rahul Singh
Rahul Singh

Reputation: 1229

You can use the whereKey:notContainedIn: method for it.Please have a look at the documentation of Parse. Here's the sudo code from the link.

// Finds scores from anyone who is neither Jonathan, Dario, nor Shawn
NSArray *names = @[@"Jonathan Walsh",
                   @"Dario Wunsch",
                   @"Shawn Simon"];
[query whereKey:@"playerName" notContainedIn:names];

Upvotes: 3

mashdup
mashdup

Reputation: 875

NSMutableArray *wantedObjects = [[NSMutableArray alloc] init];

[array enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
        if (/*do logic to match key or obj*/)
            [wantedObjects addObject:obj];
 }];

Now you can turn the above enumeration into a function. You can return [wantedObjects copy], which is an NSArray.

Upvotes: 0

Related Questions