3 struct PersistenceController {
4 static let shared = PersistenceController()
6 static var preview: PersistenceController = {
7 let result = PersistenceController(inMemory: true)
11 let container: NSPersistentCloudKitContainer
13 init(inMemory: Bool = false) {
14 container = NSPersistentCloudKitContainer(name: "Captura")
18 // Use the container to initialize the development schema.
19 try container.initializeCloudKitSchema(options: [])
26 container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null")
28 container.loadPersistentStores(completionHandler: { (storeDescription, error) in
29 if let error = error as NSError? {
30 // Replace this implementation with code to handle the error appropriately.
31 // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
34 Typical reasons for an error here include:
35 * The parent directory does not exist, cannot be created, or disallows writing.
36 * The persistent store is not accessible, due to permissions or data protection when the device is locked.
37 * The device is out of space.
38 * The store could not be migrated to the current model version.
39 Check the error message to determine what the actual problem was.
41 fatalError("Unresolved error \(error), \(error.userInfo)")
44 container.viewContext.automaticallyMergesChangesFromParent = true