Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 向具有多对多关系的核心数据中的NSSet添加对象_Objective C_Ios_Core Data_Many To Many - Fatal编程技术网

Objective c 向具有多对多关系的核心数据中的NSSet添加对象

Objective c 向具有多对多关系的核心数据中的NSSet添加对象,objective-c,ios,core-data,many-to-many,Objective C,Ios,Core Data,Many To Many,我有一个餐厅和氛围的核心数据结构,一个餐厅可以有很多氛围,一个氛围可以有很多餐厅。所以我建立了二对多的关系,正如苹果的文档中所述,二者都是相反的,形成了一种多对多的关系 但是,向创建的集合添加对象时遇到问题。例如,当我使用这样的代码时 Atmosphere *atmosphere = [Atmosphere atmosphere:aId inManagedObjectContext:context]; [restaurant addAtmospheresObject:atmosphere];

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

但是,向创建的集合添加对象时遇到问题。例如,当我使用这样的代码时

Atmosphere *atmosphere = [Atmosphere atmosphere:aId inManagedObjectContext:context];
[restaurant addAtmospheresObject:atmosphere];
它崩溃时出现了一个奇怪的错误:

EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)

有人遇到过这个问题吗?

看起来你没有正确地创建
大气对象。试试这个:

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

什么是大气*大气=[Atmosphere-Atmosphere:aId inManagedObjectContext:context];?这不是有效的语法..我在Atmosphere实体内有一个类方法(使用类别)+(Atmosphere*)Atmosphere:(NSNumber*)唯一的inManagedObjectContext:(NSManagedObjectContext*)上下文;哪一个通过唯一id字段从核心数据获取大气对象?在这个类方法之后大气变量是非nil吗?那太愚蠢了,不是!谢谢你的帮助+感谢您的努力。:-)欢迎-也试试向上投票按钮。。。别忘了打勾。