gpt4 book ai didi

objective-c - 将对象添加到具有多对多关系的核心数据中的 NSSet

转载 作者:可可西里 更新时间:2023-11-01 03:39:29 24 4
gpt4 key购买 nike

我有一个包含 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com