我有一个需要过滤的自定义 NSObject。我一直在尝试使用 NSPredicate 来执行此操作,但到目前为止还无法做到。这是我的对象的结构:
@interface MyBigObject : NSObject
@property (nonatomic, strong) NSString *firstAttribute;
@property (nonatomic, strong) NSString *secondAttribute;
@property (nonatomic, strong) NSMutableArray *featuresArray;
@end
featuresArray 包含其他自定义对象:
typedef enum {
FeatureExists = YES, //Default
FeatureDoesNotExist = NO,
FeatureNotAvailable
} FeatureValue;
@interface MySmallObject : NSObject
@property (nonatomic, strong) NSString *title;
@property (nonatomic) FeatureValue feature;
@end
我只想返回包含具有特定标题且具有功能 == FeatureExists 的 MySmallObject 的对象。
我尝试过类似(和其他变体)但没有成功:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SUBQUERY(featuresArray, $object, $object.title CONTAINS[c] %@ AND $object.feature = %d).@count > 0)", @"Fenced", FeatureExists];
NSLog(@"predicate = %@", predicate);