问题描述
在coredata中,我可以与一个实体相当好地工作,主要是因为它在互联网上记录得很好。然而,当我得到关系,我继续发现相同的数据反复,告诉我如何添加一个实体和最佳实践,但缺乏时,给我实际可用的例子。
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.
所以,这件事,我有一对多(实体之间:名称和ErgTimes)关系设置和我想知道如何添加多个对象每个名字的时间。在我的Name.m文件中有
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。
推荐答案
=http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreData/Articles/cdAccessorMethods.html#//apple_ref/doc/uid/TP40002154-SW6>自定义多对一关系存取器方法。您可以使用标准的-mutableSetValueForKey:方法访问您的关系:
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];
或者,如果您需要在多个地方执行上述操作, ergTimes属性的访问器,以便您可以直接添加时间:
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.
这篇关于CoreData添加关系多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!