将对象添加到具有多对多关系的Core Data中的NSSet

Chr*_*org 6 many-to-many core-data objective-c ios

我有一个餐厅和氛围的核心数据结构,餐厅可以有很多的气氛,气氛可以有很多餐厅.所以我建立了两对多关系,两者都是苹果文档中所述的相反,形成了多对多的关系.

但是我在创建的集合中添加对象时遇到了麻烦.例如,当我使用这样的代码时,

Atmosphere *atmosphere = [Atmosphere atmosphere:aId inManagedObjectContext:context];
[restaurant addAtmospheresObject:atmosphere];
Run Code Online (Sandbox Code Playgroud)

它崩溃了一个奇怪的错误:

EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
Run Code Online (Sandbox Code Playgroud)

有没有人遇到过这个?

Mun*_*ndi 12

看起来您没有atmosphere正确创建对象.试试这个:

Atmosphere *atmosphere = [NSEntityDescription 
   insertNewObjectForEntityForName:@"Atmosphere" 
            inManagedObjectContext:context];
// further configuration
if (restaurant) {
   [restaurant addAtmospheresObject:atmosphere];
}
Run Code Online (Sandbox Code Playgroud)

  • 欢迎 - 尝试向上投票按钮......不要忘记勾选复选标记. (2认同)