我有一个包含 Restaurants 和 Atmospheres 的核心数据结构,其中一个餐厅可以有很多氛围,一个氛围可以有很多餐厅。因此,我建立了两个对多关系,两者都与 Apple 文档中所述的自身相反,形成了一个多对多关系。
但是,我无法将对象添加到创建的集合中。例如,当我使用这样的代码时,
Atmosphere *atmosphere = [Atmosphere atmosphere:aId inManagedObjectContext:context];
[restaurant addAtmospheresObject:atmosphere];
它因奇怪的错误而崩溃:
EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
有没有人遇到过这种情况?
最佳答案
看起来您没有正确创建atmosphere
对象。试试这个:
Atmosphere *atmosphere = [NSEntityDescription
insertNewObjectForEntityForName:@"Atmosphere"
inManagedObjectContext:context];
// further configuration
if (restaurant) {
[restaurant addAtmospheresObject:atmosphere];
}
关于objective-c - 将对象添加到具有多对多关系的核心数据中的 NSSet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10056014/