我有一个我需要过滤的自定义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
我想只返回包含具有特定标题的MySmallObject的对象,并且具有== FeatureExists功能。
我尝试了类似的东西(和其他变体),但没有成功:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SUBQUERY(featuresArray, $object, $object.title CONTAINS[c] %@ AND $object.feature = %d).@count > 0)", @"Fenced", FeatureExists];
NSLog(@"predicate = %@", predicate);
答案 0 :(得分:2)
如果我理解正确,谓词的格式是错误的。如果任何对象符合要求,则应该[NSPredicate predicateWithFormat:@"SUBQUERY(featuresArray, $object, $object.title CONTAINS[c] %@ AND $object.feature = %d).@count > 0", @"some string", FeatureExists];
检查数组。