我试图在一个列表中有一个简单的ForEach(并且在另一个项目中已经这样做了(,但在这个项目中,我得到了下面提到的错误?我该如何修复?
错误
无法使用类型为"(@sescape((->ForEach,Int64,Text>("的参数列表调用类型"List"的初始值设定项
代码
import SwiftUI
struct ContentView: View {
@FetchRequest(fetchRequest: GCList.allListFetchRequest()) var gcLists: FetchedResults<GCList>
var body : some View {
NavigationView {
List { // <=== ERROR IS MARKED HERE IN XCODE
ForEach(self.gcLists) { gcList in
Text(gcList.title)
}
}
}
}
}
和
extension GCList : Identifiable {
@nonobjc public class func fetchRequest() -> NSFetchRequest<GCList> {
return NSFetchRequest<GCList>(entityName: "GCList")
}
@NSManaged public var id: Int64
@NSManaged public var title: String
}
extension GCList {
static func allListFetchRequest() -> NSFetchRequest<GCList> {
let request: NSFetchRequest<GCList> = GCList.fetchRequest()
request.sortDescriptors = [NSSortDescriptor(key: "id", ascending: true)]
return request
}
}
事实证明,在核心数据中,我创建了一个名为"List"的旧实体,它成功地完成了很多事情。。。。