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

Swift CoreData child to-many entities not accessible through parent

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

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]?
...
}

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

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

@NSManaged public var eventFights: Set<Event>