Swift CoreData子对多实体无法通过父级访问

时间:2018-10-04 16:48:17

标签: ios swift nsmanagedobject

我有一个event父实体,其中包含许多fight。所有fight条目都具有正确的event逆属性ID。我可以通过event访问fight,但是当我尝试通过访问fight获取event.fights时,出现以下错误

expression produced error: error: Execution was interrupted, reason: internal ObjC exception breakpoint(-5)..
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.

Warning: hit breakpoint while running function, skipping commands and conditions to prevent recursion.Warning: hit breakpoint while running function, skipping commands and conditions to prevent recursion.Warning: hit breakpoint while running function, skipping commands and conditions to prevent recursion.

为什么我不能通过父级访问许多子级属性?有什么办法可以解决这个问题?

类型显示为_ArrayBuffer<Schedule.Fight>

编辑1:

在对该主题进行了更多搜索之后,事实证明这是所谓的关系错误的结果,这是性能增强,意味着子实体被延迟加载。

我仍然找不到有关如何解决该问题并使child实体可访问的任何解决方案。大多数答案似乎都依赖于NSSet,但是,我的子实体被这样定义为可选数组:

extension Event {
...
@NSManaged public var arena: String
@NSManaged public var baseTitle: String
@NSManaged public var eventFights: [EventFight]?
...
}

是否可以通过在获取请求中添加某些内容或强制在子实体上加载数据来解决此问题?任何建议都会有所帮助。

1 个答案:

答案 0 :(得分:1)

核心数据对多关系必须是(无序)集合,它不能是数组,我建议将对多关系始终声明为非可选:

@NSManaged public var eventFights: Set<Event>