[英]Parse.com How to know if an array does not contain an object
there is a method for PFQuery 有一个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? 如果不是,如何自己编写此方法?
You can use the whereKey:notContainedIn:
method for it.Please have a look at the documentation of Parse . 您可以使用
whereKey:notContainedIn:
方法。请查看Parse的文档。 Here's the sudo code from the link. 这是链接中的sudo代码。
// Finds scores from anyone who is neither Jonathan, Dario, nor Shawn
NSArray *names = @[@"Jonathan Walsh",
@"Dario Wunsch",
@"Shawn Simon"];
[query whereKey:@"playerName" notContainedIn:names];
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.
您可以返回[wantedObjects copy],这是一个NSArray。
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: 如果要查找Array键不包含其他对象的对象,可以使用
notEqualTo:
由Parse开发人员在此处确认:
https://www.parse.com/questions/pfquery-not-include-any-object-in-array https://www.parse.com/questions/pfquery-not-include-any-object-in-array
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.