init(inMemory: Bool=false) { container =NSPersistentCloudKitContainer(name: "CoreDataDemo") if inMemory { container.persistentStoreDescriptions.first!.url =URL(fileURLWithPath: "/dev/null") } container.loadPersistentStores(completionHandler: { (storeDescription, error) in iflet error = error asNSError? { // Replace this implementation with code to handle the error appropriately. // 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. fatalError("Unresolved error \(error), \(error.userInfo)") } }) container.viewContext.automaticallyMergesChangesFromParent =true } }
finalclassMyPersistenceController { structConfiguration { let containerClass: NSPersistentCloudKitContainer.Type let name: String let managedObjectModel: NSManagedObjectModel? init(containerClass: NSPersistentCloudKitContainer.Type, name: String, managedObjectModel: NSManagedObjectModel? =nil) { self.containerClass = containerClass self.name = name self.managedObjectModel = managedObjectModel } } let container: NSPersistentCloudKitContainer init(_configuration: MyPersistenceController.Configuration) { iflet managedObjectModel = configuration.managedObjectModel { container = configuration.containerClass.init(name: configuration.name, managedObjectModel: managedObjectModel) } else { container = configuration.containerClass.init(name: configuration.name) } container.loadPersistentStores(completionHandler: { (storeDescription, error) in iflet error = error asNSError? { // Replace this implementation with code to handle the error appropriately. // 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. #ifDEBUG fatalError("Unresolved error \(error), \(error.userInfo)") #else #endif } }) } }