Bartłomiej Semańczyk
Bartłomiej Semańczyk

Reputation: 61774

Create NSPredicate with ANY and two conditions for it

I simply have two entities: Product and Item. Product may have many items: Set<Item>. Item has two properties: isActive and identifier.

Now I need to fetch all Products which have at least one Item with the following conditions met the same time:

But I got exception: Unable to parse the format ...

Why?

Upvotes: 1

Views: 187

Answers (1)

Tarun Tyagi
Tarun Tyagi

Reputation: 10102

You can try this -

let format = "SUBQUERY(items, $item, $item.identifier IN %@ AND $item.isActive = true).@count > 0"
let predicate = NSPredicate(format: format, ["1", "2"])

Source : NSPredicate Cheatsheet

Upvotes: 2

Related Questions