开发者

CoreData adding relationships to-many

In coredata I can work with one Entity fairly well, mostly because its nicely documented on the internet. However when i get to relationships i keep finding the same data over and over that tells me how to add one to an entity and and best practices but falls short when giving me actual useable examples.

So heres the thing, I've got a one-to-many (between entities:Name and ErgTimes) relationship set up and Im wondering how to add multiple objects to Times for every name. 开发者_如何学运维Inside my Name.m file i have

- (void)addTimesObject:(ErgTimes *)value;

but i dont know where i should use this to add in times.

Sorry for the lack of code in this example, but if anyone could just point me to a tutorial that shows the use of relationships so i can get an idea that would be so awesome.

-James.


Read Custom To-Many Relationship Accessor Methods. You can use the standard -mutableSetValueForKey: method to access your relationship:

NSMutableSet *ergTimes = [person mutableSetValueForKey:@"ergTimes"];
[ergTimes addObject:newErgTime];

Or, if you need to do the above in a number of places, you might want to implement an accessor for the 'ergTimes' property so that you can add a time directly:

[person addErgTimesObject:newErgTime];

Examples are given in the section I cited above.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜