Post

Replies

Boosts

Views

Activity

Reply to Persistent Storage for Previewing
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)")             }         }     } }
Jul ’20