gpt4 book ai didi

swift - 使用核心数据获取请求时,Xcode 错误提示 "cannot find type ' TestModelCoreData' in scope,但它编译并运行

转载 作者:行者123 更新时间:2023-12-03 09:20:25 25 4
gpt4 key购买 nike

下面的代码是我的观点,我正在处理核心数据,但它不断给我错误,即它在范围内找不到实体,但应用程序运行良好,一切都得到了保存和提取。
Here are screenshots of the errors it gives

import SwiftUI

struct ContentView: View {
@Environment(\.managedObjectContext) var moc
@FetchRequest(
entity: TestModelCoreData.entity(),
sortDescriptors: [
NSSortDescriptor(keyPath: \TestModelCoreData.name, ascending: false)
]
) var entities: FetchedResults<TestModelCoreData>

var body: some View {
VStack {
Text("Hello, world!").padding()

Button(action: {
let newEntry = TestModelCoreData(context: self.moc)
newEntry.name = "New name"

if self.moc.hasChanges {
try? self.moc.save()
}
}) {
Text("Add entry")
}

List(entities, id: \.self) { entity in
Text(entity.name ?? "Unknown")
}
}
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}

最佳答案

关于swift - 使用核心数据获取请求时,Xcode 错误提示 "cannot find type ' TestModelCoreData' in scope,但它编译并运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62888528/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com