我有三种类型的自定义类(见下文)和三个数组componentList,componentGroupList和componentGroupItemList。数组没有链接,每个数组都包含所有对象。我需要过滤特定组件,所有相关组和所有相关项目。如何使用数组过滤数组?
现在,我知道如何使用@“componentId == 123”过滤componentList并获取所需的组件对象。我也可以使用相同的谓词从componentGroupList中过滤它的组,因为ComponentGroup对象包含相同的componentId键。但是,我不知道如何从componentGroupItemList过滤相关的ComponentGroupItem对象。
目前,我过滤了包含ComponentGroup对象的数组,并且我想使用该数组过滤componentGroupItemList。是否有可能,或者我是否需要将filteredComponentGroupList中的所有“groupId”值提取到一个字符串中,然后做出一些谓词?
的类:
@interface Component : NSObject
@property (nonatomic, strong) NSNumber *componentId;
@property (nonatomic, strong) NSString *title;
@end
@interface ComponentGroup : NSObject
@property (nonatomic, strong) NSNumber *groupId;
@property (nonatomic, strong) NSNumber *componentId;
@property (nonatomic, strong) NSString *title;
@end
@interface ComponentGroupItem : NSObject
@property (nonatomic, strong) NSNumber *itemId;
@property (nonatomic, strong) NSNumber *groupId;
@property (nonatomic, strong) NSString *title;
@end
现在你8秒快速:-) - 如果我理解正确的,必要的关键是“groupId”,而不是“componentId”,但我可能是错的。 – 2013-05-07 12:42:15