1

I need a predicate almost like this:

let frOU = NSFetchRequest(entityName: "OU")
frOU.predicate = NSPredicate(format: "IN o.ous.recordName = %@ AND IN o.ous.checkedOut = true", "123")

but it would be important that the two conditions match to the same OU managed object. How can I write it?

someting like "$(o.ous) IN ($0.recordName = %@ AND $0.checkedOut = true)" but with right syntacs, is it possible with core data?

enter image description here

János
  • 32,867
  • 38
  • 193
  • 353

1 Answers1

3

This can be done with a SUBQUERY, for example

NSPredicate(format: "SUBQUERY(o.ous, $x, $x.recordName = %@ AND $x.checkedOut = true).@count > 0", "123")

finds all "OU" objects which are related to an "O" object which is related to any "OU" object with the given record name and checked-out value.

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • 1
    @János: The only Apple documentation that I know of is hidden in the NSExpression Class Reference. There are also some SO answers demonstrating the use or SUBQUERY. This http://stackoverflow.com/questions/3810992/quick-explanation-of-subquery-in-nspredicate-expression might also be useful. – Martin R Oct 04 '14 at 21:35