使用IN NSNumbers进行NSPredicate

时间:2015-11-12 10:34:44

标签: ios objective-c nspredicate nsnumber

我已经设置了一个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?

更新: 阵列:

enter image description here

Category的实体:

enter image description here

2 个答案:

答案 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];