ios - Core Data filter to many ordered relationship with predicate -


i have core data model task , list, list has to-many ordered relationship task, , task has inverse to-many relationship list. need retrieve tasks given list in correct order, filtered match predicate. example, if priority field on task,

nspredicate* predicate = [nspredicate predicatewithstring:@"priority == high"]  list* list; // fetched  

i can accomplish

nsarray* alltasks = list.tasks; nsarray* sometasks = [alltasks filteredarrayusingpredicate:predicate]; 

but requires pulling tasks memory. fetch tasks directly

nsfetchrequest* req = [[nsfetchrequest alloc] initwithentityname:@"task"]; [req setpredicate:[nspredicate predicatewithformat:@"list == %@ , priority == high", list]]; nsarray* sometasks = [context executefetchrequest:req error:&error]; 

but task order not preserved.

is there way filter relationship fault predicate?

i think following method work, though inefficient:

  1. fetch required tasks using desired predicate, ensuring fetch request's returnsobjectsasfaults property set true.
  2. create new predicate format "self in %@", passing array of tasks (from step 1) argument.
  3. filter ordered set (list.tasks) using new predicate.

that way predicate evaluated in store, without faulting in tasks, while order still determined ordered relationship.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -