【问题标题】:predicateWithFormat:argumentArray: Using all items in NSArraypredicateWithFormat:argumentArray: 使用 NSArray 中的所有项目
【发布时间】:2014-02-11 13:49:00
【问题描述】:
- (void)filterViaCategories:(NSArray *)array   {
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(todo_category_id == %@)" argumentArray:array]; 
}

但是当我用过时:

po predicate

结果是:

todo_category_id == 41123..

它只是使用数组的零索引元素中的 41123

我希望数据库中所有类别的所有 id 都存在于数组中,而不是索引为零的唯一对象: (todo_category_id == 41123, 41234, 33455)

我该怎么做?

【问题讨论】:

    标签: core-data nsarray nspredicate nsfetchrequest predicatewithformat


    【解决方案1】:

    那么你不应该使用predicateWithFormat:argumentArray:,你需要改变你的格式。

    你想要这样的东西:

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"todo_category_id IN %@", array]; 
    

    【讨论】:

    • 但我给我一个错误,如:[__NSCFNumber countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance
    • 我的数组里面有 NSNumber 元素..我可以将它们更改为“ids”的字符串值吗?
    • todo_category_id 是字符串属性吗?但是数组只包含数字?
    • 那么看起来你实际上并没有向方法发送数组,你只是发送了一个单独的 NSNumber 实例......
    • 我检查了数组内部..它的计数为 3,我在其索引处打印的值为 1254,8765,9853
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-27
    • 1970-01-01
    • 2012-10-09
    • 2011-08-02
    • 2012-04-15
    • 1970-01-01
    • 2011-04-27
    相关资源
    最近更新 更多