【发布时间】:2023-03-25 05:00:02
【问题描述】:
我正在使用 CoreData 和 iCloud 在设备之间同步数据。
每次 iCloud 导入后(观察 NSPersistentStoreDidImportUbiquitousContentChangesNotification),我运行一个简单的重复数据删除算法来查找和删除重复数据。
保存更改后,我在控制台中看到来自 CoreData 的警告,即特定实体实例(已被重复数据删除算法删除)的所有属性和关系都被替换为 nil/0。
CoreData: warning: An NSManagedObjectContext delegate overrode fault handling behavior to silently delete the object with ID '0xd000000000040006 <x-coredata://ADDDABCD-4891-4DCF-B55B-53AA64D11922/<ENTITY_NAME>/p1>' and substitute nil/0 for all property values instead of throwing.
问题是该实体中的一个关系不是可选的,这会在 iCloud 下次想要在其他设备上导入这些更改时产生错误。
-[_PFUbiquityRecordsImporter operation:failedWithError:](979): CoreData: Ubiquity: Import operation encountered had trouble importing log file, Error Domain=NSCocoaErrorDomain Code=134302 "The operation couldn’t be completed. (Cocoa error 134302.)"
[...], an error occurred saving changes to the persistent store mutated during the import process. [...]
"The operation couldn’t be completed. (Cocoa error 1560.)"} User Info: { [...]
NSValidationErrorObject=<NSManagedObject: 0x1742c7bd0> (entity: <ENTITY_NAME>; [...]
{NSValidationErrorKey=<NON-OPTIONAL_RELATIONSHIP_NAME> [...]
"Error encountered while importing transaction log at URL: ...
如何避免所有属性都设置为 nil/0?
【问题讨论】: