Calling method on object in NSPredicate with Core Data

394 views Asked by At

I have a 'position' entity with a to-many relationship to 'employee's. I want to use NSPredicate to do something like this

[position.employees containsObject:meEmployee]

There is a call to perform NSPredicate with block, but sadly it can't be used with CoreData.

How can I do this?

1

There are 1 answers

0
pbasdf On BEST ANSWER

If you are fetching position entities with any employees matching meEmployee then you can use a predicate like this:

NSPredicate *predicate = [NSPredicate predicateWithFornat:@"ANY employees == %@", meEmployee];

But if the inverse relationship for employees is position, you can achieve the same with:

meEmployee.position