Вы должны получить описание контейнера и затем установить URL:
let momdName = "MyModel"
guard let modelURL = Bundle(for: type(of: self)).url(forResource: momdName, withExtension:"momd") else {
fatalError("Error loading model from bundle")
}
guard let mom = NSManagedObjectModel(contentsOf: modelURL) else {
fatalError("Error initializing mom from: \(modelURL)")
}
guard let containerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.my-group")?.appendingPathComponent("My.sqlite") else {
fatalError("Cannot get shared group URL")
}
let container = NSPersistentCloudKitContainer(name: momdName, managedObjectModel: mom)
guard let description = container.persistentStoreDescriptions.first else {
fatalError("###\(#function): Failed to retrieve a persistent store description.")
}
description.url = containerURL
container.loadPersistentStores() { (storeDescription, error) in
if let error = error as NSError? {
// ...
}
}