What I'm still encountering in some cases is this error:
** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'executeFetchRequest:error: A fetch request must have an entity.'
terminating with uncaught exception of type NSException
Post
Replies
Boosts
Views
Activity
I was able to fix this by moving my data store into its own class and using the same thing for both the app and previews:
import CloudKit
import CoreData
import Foundation
class DataStore {
static let shared = DataStore()
lazy var persistentContainer: NSPersistentContainer = {
let container = NSPersistentCloudKitContainer(name: "Structure")
container.loadPersistentStores(completionHandler: { _, error in
if let error = error {
fatalError("Unresolved error \(error)")
}
let context = container.viewContext
context.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
context.automaticallyMergesChangesFromParent = true
// other setup here
})
return container
}()
func saveContext() {
let context = persistentContainer.viewContext
if context.hasChanges {
do {
try context.save()
} catch {
fatalError("Unresolved error \(error)")
}
}
}
}
This appears to only work when a TextEditor or TextField is focused - am I missing a way to do this just based on the current window?