开发者

Fill relationships Core Data

I´m trying to create new elements in my database. I can fill all the attributes from my new element but I can fill its relatioship. Anybody knows how 开发者_如何学运维can I do that??

I fill the new element like that:

NSManagedObject *mo = [NSEntityDescription insertNewObjectForEntityForName:@"People"
                                                    inManagedObjectContext:context];
[mo setValue:label_name.text forKey:@"name"];
[mo setValue:label_surname.text forKey:@"surname"];

Thank you!!


For to-one relationships, you

  1. Create the object that should be related
  2. Use setValue:forKey: the same as you would for an attribute.

For to-many relationships, you

  1. Create the object that should be related
  2. Use mutableSetValueForKey on the originating object to add the new object to the relationship.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜