6

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?

4
  • So you want to run a query where the key does not contain any of the objects you specify? Commented Nov 14, 2013 at 17:01
  • Yes, that is exactly what i want. Commented Nov 15, 2013 at 15:56
  • 1
    Today I solved similar issue by writing function in cloud code. Commented Nov 15, 2013 at 16:19
  • 1
    would u kindly describe what u did? Commented Nov 16, 2013 at 17:19

3 Answers 3

3

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];
Sign up to request clarification or add additional context in comments.

1 Comment

@TrenboloneA Does this actually work? It's not obvious from the documentation that the key given to whereKey: can actually be an array. playerName just looks like a string field...
0
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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.