I use SwiftData, CloudKit, and App Groups. An error occurs on the first run, but it works on the second run.
error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate tearDown:]_block_invoke(792): <NSCloudKitMirroringDelegate: 0x12df73750>: Told to tear down with reason: Store Removed
error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _performSetupRequest:]_block_invoke(1192): <NSCloudKitMirroringDelegate: 0x12df73750>: Failed to set up CloudKit integration for store: (null)
Error Domain=NSCocoaErrorDomain Code=134060 "" UserInfo={NSLocalizedFailureReason=The mirroring delegate could not initialize because it's store was removed from the coordinator.}
I don't know why store path is null in error message. I passed the store url and CloudKit database name in ModelConfiguration.
static var release: ModelContainer = {
do {
let schema = Schema(versionedSchema: ModelSchema.self)
let appGroupURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group-identifier")
let databaseURL = appGroupURL?.appending(path: "Database.sqlite")
let databaseName = "Database"
let configuration = ModelConfiguration(schema: schema,
url: databaseURL!,
cloudKitDatabase: .private("iCloud.database.name"))
return try ModelContainer(for: schema,
migrationPlan: ModelMigrationPlan.self,
configurations: [configuration])
} catch {
fatalError(error.localizedDescription)
}
}()