@FetchRequest annotation in SwiftUI with Core Data

Ehs*_*san 3 xcode core-data swift swiftui

How do I use @FetchRequest with a CoreData entity Post that has Codegen: Class Def. set in Xcode? So I don't create the Post" entity class manually, but let Xcode generate it?

I now get a

Use of undeclared type Post

as an error on the last line.

@FetchRequest(entity: Post.entity(), sortDescriptors: [ 
    NSSortDescriptor(keyPath: \Post.date, ascending: true)
]) 
var posts: FetchedResults<Post> // Use of undeclared type ´Post´
Run Code Online (Sandbox Code Playgroud)

数据模型

小智 5

核心数据有时可能有问题。尝试退出 Xcode 并重新打开它。