Swift - Combining Predicates

ⅰ亾dé卋堺 提交于 2019-12-05 01:50:23
Glorfindel

You'll need NSCompoundPredicate:

let predicate1 = NSPredicate(format: "self.label = 'foo'", argumentArray: [])
let predicate2 = NSPredicate(format: "self.label = 'bar'", argumentArray: [])
let compound = NSCompoundPredicate(andPredicateWithSubpredicates: [predicate1, predicate2])
let predicate1:NSPredicate = NSPredicate("self.label = 'foo'")
let predicate2:NSPredicate = NSPredicate("self.label = 'bar'")
let compound:NSCompoundPredicate = NSCompoundPredicate(andPredicateWithSubpredicates: [predicate1,predicate2])
self.filteredArray = self.array.filteredArrayUsingPredicate(compound)
self.table.reloadData()

You can use this also as per your different requirement

let compound:NSCompoundPredicate = NSCompoundPredicate(orPredicateWithSubpredicates: [predicate1,predicate2])
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!