使用NSPredicate按对象属性过滤

eme*_*gro 3 iphone array-filter

我有一个可变的自定义对象数组.我想按对象的属性过滤该数组,例如myObject.attributeOne.

如何创建要使用的NSPredicate

[myArrayOfObjects filterUsingPredicate:<the_predicate>]
Run Code Online (Sandbox Code Playgroud)

iPh*_*Dev 7

以这种方式使用它:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"FriendStatus == 1"];

NSMutableArray *filtered = [MessageArray filteredArrayUsingPredicate:predicate];
Run Code Online (Sandbox Code Playgroud)