我已经设置了一个NSPredicate来检查NSArray数字中的对象category_id
是否为IN
。
代码:
///This is working
NSArray *arr2 = [[NSArray alloc]initWithObjects:@[@3,@2,@3],nil];
[NSPredicate predicateWithFormat:@"category_id IN %@", arr2]
//This is not working
NSArray *arr = [[NSArray alloc]initWithArray:category_array]; //Array with NSNumbers
[NSPredicate predicateWithFormat:@"category_id IN %@", arr]
这工作正常但在我将category_array
更改为包含NSNumber后,谓词停止工作。我如何使用NSPredicate for NSNumber?
更新: 阵列:
Category
的实体:
答案 0 :(得分:0)
You are making minor but blatant mistake here. You are adding an array @[@1,@2,@4]
as an object in the array category_array
.
Try:
NSArray *category_array = [[NSArray alloc] initWithArray:@[@1,@2,@4]];
or simply
NSArray *category_array = @[@1,@2,@4];
答案 1 :(得分:0)
You are making a little mistake
try out this code
NSArray *category_array = @[@1,@2,@4];