NSPredicate: Combine CONTAINS with IN

后端 未结 4 830
庸人自扰
庸人自扰 2020-11-29 09:42

I have a set of users in CoreData and an search field in my application. User has the properties firstname and name.

Currently I have a predicate like \"user.name CO

4条回答
  •  一生所求
    2020-11-29 10:19

    Swift 4 Update:

    let firstName = NSPredicate(format: "firstName CONTAINS[c] %@", searchText)
    let lastName = NSPredicate(format: "lastName CONTAINS[c] %@", searchText)
    
    let orCompoundPredicate = NSCompoundPredicate(orPredicateWithSubpredicates: 
    [firstNamePredicate,lastNamePredicate]
    

    Use the orCompoundPredicate while fetching data.

提交回复
热议问题