0

I am using NSPersistentCloudKitContainer in my Application, and I am struggling to understand when and how often should I call the method initializeCloudKitSchema() of my container.

Do I understand correctly that this is something to use in development to update the development schema update in CloudKit backend?

Should my App in production, in hands of my user ever call this method?

Here is the code that I am using:

import CoreData
import Foundation

final class DataController: ObservableObject {
    
    let container = NSPersistentCloudKitContainer(name: "MyAmazingSchema")
    
    init() {
        container.loadPersistentStores {
            description, error in
            
            if let error = error as NSError? {
                fatalError("Core Data - Unresolved error \(error), \(error.userInfo)")
            }
        }
                 
        do {
            // Should I do this ⬇️ in Production? 
            try container.initializeCloudKitSchema()
        }
        catch {
            print(error)
        }
        
        container.viewContext.automaticallyMergesChangesFromParent = true
    }
}
StuckOverFlow
  • 851
  • 6
  • 15

0 Answers0