ios - How to write a Core Data predicate for objects which are related to an object in a to-many relationship -


entitya has to-many relationship entityb (and entityb has to-one relationship entitya). have array of entitybs (or more accurately, have nsarray contains instances of nsmanagedobject represent entityb). want create nsfetchrequest fetch entityas have relationship @ least 1 of entitybs in array. how write predicate fetch request?

the following works, think sub-optimal; it's hard grok , i'm sure there must better way of expressing this:

nsarray *entitybs = ...; nsmutablearray *containsentitybsubpredicates = [nsmutablearray new]; (nsmanagedobject *entityb in entitybs) {     [containsentitybsubpredicates addobject:[nspredicate predicatewithformat:@"%@ in entitybs", entityb]]; } nspredicate *containsentitybspredicate = [nscompoundpredicate orpredicatewithsubpredicates:containsentitybsubpredicates]; 

i've tried this, doesn't work:

nsarray *entitybs = ...; nspredicate *containsentitybspredicate = [nspredicate predicatewithformat:@"any %@ in entitybs", entitybs]; 

am missing simpler solution?

you there predicate, switch parameters:

[nspredicate predicatewithformat:@"any entitybs in %@", entitybarray]; 

look @ apple's example code in here further explanation.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -