尝试使用EnvironmentObject从Core Data中填充数据。
struct ContentView : View {
@EnvironmentObject var quoteStore: QuoteStore
var body: some View {
HStack {
Text(quote.text)
Spacer()
}
}
}
这是NSManagedObject:
extension Quote {
public class func fetchRequest() -> NSFetchRequest<Quote> {
return NSFetchRequest<Quote>(entityName: "Quote")
}
@NSManaged var text: String
@NSManaged var title: String
@NSManaged var author: String
static func create(author: String, text: String, title: String, in context: NSManagedObjectContext) {
let newQuote = Quote(context: context)
newQuote.text = text
newQuote.title = title
newQuote.author = author
}
我收到错误消息“表达式类型是模棱两可的,没有更多上下文”