1

我有一个需要过滤的自定义 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);
4

1 回答 1

2

如果我理解正确,您的谓词格式是错误的。如果任何对象符合要求,它应该是[NSPredicate predicateWithFormat:@"SUBQUERY(featuresArray, $object, $object.title CONTAINS[c] %@ AND $object.feature = %d).@count > 0", @"some string", FeatureExists];您签入数组的位置。

于 2013-06-20T13:50:36.480 回答