ios - Core Data - Select by relationship -



ios - Core Data - Select by relationship -

i have 1 many relationship between father , son entities, father may have no or n son. using core data, how son, basing search father.

for example: have father owns id 1. need fetch son has father id 1.

here illustration working nsmanagedobject (subclassing easier).

nsfetchrequest *request = [[nsfetchrequest alloc] init]; [request setentity:[nsentitydescription entityforname:@"father" inmanagedobjectcontext:your_managedobjectcontext]]; // speak utilize id, word reserved improve utilize resourceid or nspredicate *predicate = [nspredicate predicatewithformat:@"resourceid=1"]; [request setpredicate:predicate]; nsarray *result = [your_managedobjectcontext executefetchrequest:request error:nil]; nsmanagedobject *father_id1 = [result firstobject]; nsset *sons = [father_id1 valueforkey:@"thenameofyourrelationshipsons"];

ios objective-c iphone core-data swift

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -