核心数据。 Fetchrequest 有关系的所有实体

CoreData. Fetchrequest all entities with relations

我的主要实体叫做系列。 Series 与名为 Rounds 的实体具有一对多关系,通过一对多(有序)连接,而 Rounds 再次具有带有 Shots 的 NSOrderedSet。 Shots 实体有一个名为 score 的属性,它是一个整数。

我想要的是从镜头实体中获取属于特定系列的所有分数。

let shots = currentSeries.rounds.shots as [Shots]

由于错误消息:"Value of type 'NSOrderedSet' has no member: 'shots'",所以没有给我所有要迭代的镜头。不知何故,我需要为 "Shots" 实体设置一个谓词,它过滤属于特定 "Series" entity.The 系列实体的所有镜头没有唯一标识符,但我想它可以可以使用时间戳属性来隔离特定的 "Series"。但同样,我想要所有 "Shots" 实体,连接到特定 "Series".

我可能非常需要有关 CoreData 挖掘的一些帮助,或者至少需要一些有关如何完成我的工作的建议。

获取给定 Series 的所有 Shots 的一种方法是使用谓词获取:

let fetch = NSFetchRequest(entityName:"Shots")
let fetch.predicate = NSPredicate(format:"rounds.series == %@", currentSeries)
let currentSeriesShots = try! context.executeFetchRequest(fetch) as! [Shots]

(您应该添加适当的错误处理)。无需使用唯一标识符 - CoreData 将为 currentSeries 对象使用自己的(内部)标识符来确定 Shots 到 return.