Joseph
Joseph

Reputation: 9351

CoreData Fetched Property referring to a different entity

I have a CoreData Entity named List it has a Relationship to an Entity Address. This is a one-to-many relationship seeing as an Address can be only be one List.

Address entities have an Attribute flag which is an Integer 16.

Is there a way for me to define a Fetched Property in the List entity with a count of all related Address entities that have their flag set to 1? What would the predicate look like?

Thanks

Upvotes: 0

Views: 341

Answers (1)

Razvan
Razvan

Reputation: 4122

Yes, you can do it like this:

Create a fetch request for the List entity and set its predicate to:

[NSPredicate predicateWithFormat:@"address.flag == %@", @1]

Also don't forget to prefetch relationship so you don't encounter any cache misses.

Upvotes: 0

Related Questions