В журналах постоянно отображается следующее:
Код: Выделить всё
CoreData: debug: CoreData+CloudKit: -[NSCloudKitMirroringDelegate remoteStoreDidChange:]_block_invoke_2(3216):
- Ignoring remote change notification because it didn't change any entities tracked by persistent history:
(URL: file:///var/mobile/Containers/Data/Application/62AABD0C-972D-4477-BB81-DA2F385B5B43/Library/Application%20Support/CloudDataModel.sqlite)
Код: Выделить всё
CoreData: debug: CoreData+CloudKit: -:
Skipping migration for 'ANSCKRECORDMETADATA' because it already has a column named 'ZNEEDSUPLOAD'
Код: Выделить всё
lazy var cloudContainer: NSPersistentCloudKitContainer = {
let container = NSPersistentCloudKitContainer(name: "CloudDataModel")
guard let description = container.persistentStoreDescriptions.first else {
fatalError("Failed to retrieve store description")
}
description.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey)
description.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey)
let containerIdentifier = "iCloud.com.integralstudios.kalo"
description.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: containerIdentifier)
container.loadPersistentStores { description, error in
if let error = error {
print("❌ Unable to load cloud persistent stores: \(error)")
}
}
container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
container.viewContext.transactionAuthor = "integralstudios.kalo"
container.viewContext.automaticallyMergesChangesFromParent = true
do {
try container.viewContext.setQueryGenerationFrom(.current)
try container.initializeCloudKitSchema()
} catch {
print("⚠️ Failed to initialize CloudKit schema: \(error)")
}
return container
}()
Код: Выделить всё
func save() {
let localContext = localContainer.viewContext
let cloudContext = cloudContainer.viewContext
if localContext.hasChanges {
do {
try localContext.save()
} catch {
print("Error saving local context: \(error)")
}
}
if cloudContext.hasChanges {
do {
try cloudContext.save()
} catch {
print("Error saving cloud context: \(error)")
}
}
}
Код: Выделить всё
✅ CloudKit schema initialized successfully
✅ Audio session configured successfully
✅ Using shared PersistenceController instance
✅ Verified 6 meals in cloud context
✅ SharedDataManager: UserDefaults created
✅ SharedDataManager: Defaults registered
✅ SharedDataManager: Successfully verified write access
- NSCloudKitMirroringDelegate наблюдает за изменениями, но многие пропускает уведомления.
- Похоже, что постоянные изменения истории не отслеживаются должным образом.
- Некоторые миграции пропускаются из-за существующих столбцов.
Подробнее здесь: https://stackoverflow.com/questions/793 ... migrations