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
- Create the object that should be related
- Use
setValue:forKey:
the same as you would for an attribute.
For to-many relationships, you
- Create the object that should be related
- Use
mutableSetValueForKey
on the originating object to add the new object to the relationship.
精彩评论