RileyDev
RileyDev

Reputation: 2535

How to use two NSPredicates for fetch request - Swift 2

I was trying to use two NSPredicates for a single fetch request by doing,

let predicate1 = NSPredicate(format: "object1 == nil", "object1")
let predicate2 = NSPredicate(format: "object2 == nil", "object2")
let predicate = NSCompoundPredicate(type: NSCompoundPredicateType.OrPredicateType, subpredicates: [predicate1, predicate2])

request.predicate = predicate

the objects are a subclass of NSManagedObject and I am trying to fetch all items that have not got a relation with either object.

However it does not seem to be working, can someone have any suggestions on where I may be going wrong ?

Upvotes: 0

Views: 135

Answers (1)

Manikandan D
Manikandan D

Reputation: 1442

Try this,

let predicate1 = NSPredicate(format: "object1 == nil && object2 == nil", "object1","object2")

Upvotes: 3

Related Questions