我需要根据另一个数组中对象的属性过滤数组。 假设我有两个类:
商店列表.h
@interface StoreList : NSObject {
NSMutableArray *storesArray; //Array containing Store objects
}
商店.h
@interface Store : NSObject {
NSString *name;
}
因此,我有一个 NSArray (storeListArray),其中包含一些 StoreList 对象。然后,我的 Array 是这样的:
storeListArray = [
StoreList:{
storesArray: {
stores[{
store: {
name: "Store1"
},
store: {
name: "Store2"
}
}]
},
storesArray: {
stores[{
store: {
name: "Store1"
},
store: {
name: "Store2"
}
}]
}
}
];
那么,我的问题是:如何使用 NSPredicate 通过存储对象的“名称”属性过滤 storeListArray?
我正在尝试做这样的事情,但这不起作用:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY storeList CONTAINS[cd] %@", filterString];
self.filteredStores = [storeListArray filteredArrayUsingPredicate:predicate];
return self.filteredStores;
感谢您的帮助!
最佳答案
试试这个,
NSPredicate * predicate = [NSPredicate predicateWithFormat:@"ANY SELF.storesArray.name == %@", filterString];
NSArray * videoArray = [storeListArray filteredArrayUsingPredicate:predicate];
关于ios - 使用 NSPredicate 过滤对象中的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22542970/