- Project create usinging
Xcode macOS Document App
template, withUse Core Data
checkbox checked. - Add a Book entity to
Document.xcdatamodeld
- Add FetchRequest warp property to
ContentView
,
@FetchRequest(entity: Book.entity(), sortDescriptors: []) var books: FetchedResults<Book>
- Build and Run, Crash!
Crash log from console is
2020-07-03 23:12:23.597880+0800 DocMacDemo[15236:4376209] [error] error: No NSEntityDescriptions in any model claim the NSManagedObject subclass 'DocMacDemo.Book' so +entity is confused. Have you loaded your NSManagedObjectModel yet ?
CoreData: error: No NSEntityDescriptions in any model claim the NSManagedObject subclass 'DocMacDemo.Book' so +entity is confused. Have you loaded your NSManagedObjectModel yet ?
2020-07-03 23:12:23.598287+0800 DocMacDemo[15236:4376209] [error] error: +[DocMacDemo.Book entity] Failed to find a unique match for an NSEntityDescription to a managed object subclass
CoreData: error: +[DocMacDemo.Book entity] Failed to find a unique match for an NSEntityDescription to a managed object subclass
2020-07-03 23:12:23.644491+0800 DocMacDemo[15236:4376209] executeFetchRequest:error: A fetch request must have an entity.
2020-07-03 23:12:23.653769+0800 DocMacDemo[15236:4376209] [error] error: The fetch request's entity 0x600003500420 'Book' appears to be from a different NSManagedObjectModel than this context's
CoreData: error: The fetch request's entity 0x600003500420 'Book' appears to be from a different NSManagedObjectModel than this context's
(lldb)
I have looking for NSPersistentDocument SwiftUI example several days, but could NOT find one. Here are some similar or relation questions. Unfortunately, this problem is not solved.
- Using @fetchRequest(entity: ) for SwiftUI macOS app crashes
- SwiftUI @FetchRequest crashes the app and returns error
- https://developer.apple.com/forums/thread/124656?answerId=417869022#417869022
- https://developer.apple.com/forums/thread/132624
EDIT: Upload this issue project to Github, https://github.com/donly/DocMacDemo.