1 | initial version |
You can create multiple NSPredicates and combine them using NSCompoundPredicate. Here's an example:
let agePredicate = NSPredicate(format: "age > %d", 18)
let namePredicate = NSPredicate(format: "name CONTAINS %@", "John")
let compoundPredicate = NSCompoundPredicate(andPredicateWithSubpredicates: [agePredicate, namePredicate])
let fetchRequest: NSFetchRequest<Person> = Person.fetchRequest()
fetchRequest.predicate = compoundPredicate
let results = try? context.fetch(fetchRequest)
In this example, we have two NSPredicates: one for age and one for name. We then combine them using NSCompoundPredicate with the "AND" operator and set it as the fetch request's predicate. Finally, we execute the fetch request and get the results.