ios - How to Insert Core Data Record Related to Another? -


currently have 2 entities in model; module , level. have 1 many relationship e.g. level can have lot of modules. how can can insert data related 1 can module has specific year. need when delete module deletes year.

module<<---->level

if add objects separately works fine, add last line of code application crashes says entity module not key value coding compliant key level_number name of relationship on module side.

nsmanagedobject *newmodule; newmodule = [nsentitydescription               insertnewobjectforentityforname:@"module"               inmanagedobjectcontext:context];  [newmodule setvalue:textmodueltitle.text forkey:@"name"]; [newmodule setvalue:value forkey:@"credit"];      nsmanagedobject *newlevel;     newlevel = [nsentitydescription                  insertnewobjectforentityforname:@"level"                  inmanagedobjectcontext:context];        [newlevel setvalue:year forkey:@"value"];      [[newmodule mutablesetvalueforkey:@"level_number"] addobject:newlevel]; 

when have 1 many relationship, set values 1 side , core data take care of other side.

since level has 1 one relationship module. set module level , save context.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -