在SwiftUI中使用Core Data时,“表达类型不明确,没有更多上下文”

时间:2019-07-01 21:20:03

标签: core-data swiftui

尝试使用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
    }

我收到错误消息“表达式类型是模棱两可的,没有更多上下文”

0 个答案:

没有答案