Back again needing more help with constructing my NSPredicates :(
Category
{
name:string
subs<-->>SubCategory
}
SubCategory
{
name:string
For Swift, this is how you can do it:
SWIFT 4.x - AND
let p0 = NSPredicate(format: "X == 1")
let p1 = NSPredicate(format: "Y == 2")
fetchRequest.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: [p0, p1])
SWIFT 4.x - OR
let p0 = NSPredicate(format: "X == 1")
let p1 = NSPredicate(format: "Y == 2")
fetchRequest.predicate = NSCompoundPredicate(orPredicateWithSubpredicates: [p0, p1])
SWIFT 4.x - NOT
let p0 = NSPredicate(format: "X == 1")
let p1 = NSPredicate(format: "Y == 2")
fetchRequest.predicate = NSCompoundPredicate(notPredicateWithSubpredicates: [p0, p1])
Example
This is an example from one of my codes, where I look for uid and sync:
let p0 = NSPredicate(format: self.uid + " = '" + uid + "'")
let p1 = NSPredicate(format: self.sync + " = %@", NSNumber(value: true as Bool))
fetchRequest.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: [p0, p1])