app*_*eak 1 nsmutablearray nspredicate ios
我有一个自定义类扩展NSObject.我正在维护NSMutableArray这个类对象.这是情况,
customObject-class {
NSString *name;
int ID;
.....and many other properties;
}
customObjectsArray [
customObject1,
customObject2,
...etc
]
Run Code Online (Sandbox Code Playgroud)
现在我尝试使用filterUsingPredicate删除具有nil名称的对象,如下所示,但它返回的对象很少或没有,而我知道有数百个对象的名称不是nil或为空.有人可以告诉我这里可能有什么问题.
[customObjectsArray filterUsingPredicate:[NSPredicate predicateWithFormat:@"name != nil"]];
Run Code Online (Sandbox Code Playgroud)
小智 5
你为什么不这样做:
NSMutableArray *array=...;
[array filterUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
CustomObject *customObject=(CustomObject *) evaluatedObject;
return (customObject.name!=nil);
}]];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3211 次 |
| 最近记录: |