我有一个自定义类扩展NSObject
。我正在维护此类对象的NSMutableArray
。这是情况
customObject-class {
NSString *name;
int ID;
.....and many other properties;
}
customObjectsArray [
customObject1,
customObject2,
...etc
]
现在,我尝试使用filterUsingPredicate删除名称为nil的对象,如下所示,但它返回的对象很少或没有,而我知道有数百个名称为nil或为空的对象。有人可以告诉我这里有什么问题吗。
[customObjectsArray filterUsingPredicate:[NSPredicate predicateWithFormat:@"name != nil"]];
最佳答案
为什么不这样尝试:
NSMutableArray *array=...;
[array filterUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
CustomObject *customObject=(CustomObject *) evaluatedObject;
return (customObject.name!=nil);
}]];
关于ios - iOS:自定义对象上的FilterUsingPredicate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13906322/