HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了AND和OR结合NSPredicate. IOS斯威夫特大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的coredata获取查询的动态或谓词 @H_616_5@ @H_616_5@
var preDicate = [NSPreDicate]()
    //this three is or
        preDicate.append(NSPreDicate(format: "item_parent_id = %i",1))
        preDicate.append(NSPreDicate(format: "item_parent_id = %i",3))       
        preDicate.append(NSPreDicate(format: "item_parent_id = %i",5))

    // but this one is and
        preDicate.append(NSPreDicate(format: "price_date CONTAINS[cd] %@",'timestamp'))

    var compound = NSCompoundPreDicate.orPreDicateWithSubpreDicates(preDicatE)
@H_616_5@OR运算符的前三个约束,日期的最后一个约束是AND

@H_616_5@我花了很多时间来做这件事,我是快速发展的新手,我不习惯于目标C,这就是为什么我很难转换为我在客观c中写的快速翻译.

@H_616_5@如果可能的话,快速写下答案,任何评论和建议都将是一个很大的帮助.提前致谢

@H_616_5@obj c – source #1
obj c – source #2

解决方法

如果你正在寻找像(a OR b OR C)和d这样的操作,你需要两个复合谓词: @H_616_5@ @H_616_5@
var orList = [NSPreDicate]()
//this three is or
orList.append(NSPreDicate(format: "item_parent_id = %i",1))
orList.append(NSPreDicate(format: "item_parent_id = %i",3))       
orList.append(NSPreDicate(format: "item_parent_id = %i",5))
let orPreDicate = NSCompoundPreDicate.orPreDicateWithSubpreDicates(orList)

// but this one is and
let other = NSPreDicate(format: "price_date CONTAINS[cd] %@",'timestamp')

let compound = NSCompoundPreDicate.andPreDicateWithSubpreDicates([orPreDicate,other])

大佬总结

以上是大佬教程为你收集整理的AND和OR结合NSPredicate. IOS斯威夫特全部内容,希望文章能够帮你解决AND和OR结合NSPredicate. IOS斯威夫特所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。