【发布时间】:2016-11-22 18:44:02
【问题描述】:
我是一个快速的初学者,我想为我编写一个小应用程序,但我遇到了问题。我的应用包含三个实体(模板、记录和位置),您可以在这里看到:
在应用程序的一部分,我可以添加新记录,并为该记录添加一些职位(xpos 和 ypos)。
在我列出我的记录时,我有一个表格视图。现在我想单击表中的一条记录,并且我想获取与特定选定记录链接的所有位置属性。
使用该代码,我可以获得all xpos-Positions,但我怎样才能获得single xpos? :)
guard let moc = self.managedContext else {
return
}
let fetchRequest: NSFetchRequest<Records> = Records.fetchRequest()
do {
let searchResults = try moc.fetch(fetchRequest)
let xpos = searchResults[0].positions?.mutableArrayValue(forKey: "xpos")
print(xpos)
} catch {
print("Error with request: \(error)")
}
【问题讨论】:
标签: swift core-data relationship one-to-many