【发布时间】:2020-02-09 18:49:23
【问题描述】:
我想显示存储为 NSManagedObjects 的 CoreData 记录列表。
我想做这样的事情:
struct RecordView: View
{
@State var records:[MyRecord] //[NSManagedObject]
var body: some View
{
VStack
{
List(records) {record in // Error: Initializer 'init(_:rowContent:)' requires that 'Record' conform to 'Identifiable'
RecordRow(record: record)
}
}
}
struct RecordRow: View {
var record: Record //NSManagedObject
var body: some View
{
NavigationLink(destination: RecordForm(record: record))
{
HStack
{
Text(record.name)
.frame(width: 140, height: 50, alignment: .leading)
}
}
}
我遇到了一个错误
Initializer 'init(_:rowContent:)' requires that 'Record' conform to 'Identifiable'
我错过了什么?
【问题讨论】:
-
查看文档中可识别的协议并以某种方式采用它