【问题标题】:NSPredicate to use IN and LIKE at the same timeNSPredicate 同时使用 IN 和 LIKE
【发布时间】:2012-05-01 12:55:35
【问题描述】:

我有一个搜索值数组,我想在 NSPredicate 中与 LIKE 查询结合使用:

NSPredicate *p = [NSPredicate predicateWithFormat:@"textField IN LIKE[c] %@", array];

这不起作用,但是这是否可以查看 textfield 对数组中的每个值是否有任何 LIKE 比较?

【问题讨论】:

    标签: iphone ios core-data nspredicate


    【解决方案1】:

    您应该使用NSCompoundPredicate。它让您可以将一系列 LIKE 谓词与 OR 结合起来。

    NSMutableArray *subpredicates = [NSMutableArray array];
    for(NSString *text in array)
     [subpredicates addObject:[NSPredicate predicateWithFormat:@"textfield LIKE %@",text]];
    NSPredicate *finished = [NSCompoundPredicate orPredicateWithSubpredicates:subpreds];//Your final predicate 
    

    【讨论】:

    • 是否可以这样做:WHERE x = 0 AND y = 0 AND (field IN array OR anotherField LIKE[c] array
    • orCompoundPredicateWithSubpredicatesandCompoundPredicateWithSubpredicates 分别构成 ORAND 谓词。你可以按照你想要的方式组合它们
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-18
    相关资源
    最近更新 更多