Core data + CloudKit - sharing between iOS and watchOS companion app

后端 未结 1 1460
日久生厌
日久生厌 2021-02-09 12:35

In my app I store data with core data. Recently I discovered the new feature introduced by Apple in WWDC19 which allows core data to work with CloudKit. I just enabled cloudKit

相关标签:
1条回答
  • 2021-02-09 13:11

    Resolved by adding a cloudKitContainerOptions to my context description like this :

    class CoreDataStack {
        static let persistentContainer: NSPersistentCloudKitContainer = {
            let container = NSPersistentCloudKitContainer(name: "MyProjectName")
            let description = container.persistentStoreDescriptions.first
    
            description?.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: "myCloudContainerID") // HERE !
    
            container.loadPersistentStores(completionHandler: { (_, error) in
                if let error = error as NSError? {
                    fatalError("Unresolved error \(error), \(error.userInfo)")
                }
            })
            return container
        }()  
    
    }
    
    0 讨论(0)
提交回复
热议问题