我使用 CoreData + NSPersistentCloudKitContainer 来备份我的模型。我的一个 NSManagedObject 有一张存储为二进制数据的图片,并检查了允许外部存储。
这是非常随机的,但有时当我打电话时,context.save()
即使我没有编辑此对象,我也会遇到合并冲突。实际上,我只是尝试创建一个新对象(与具有冲突的对象不同的类型)并且崩溃发生在另一个对象上。
除了 的自引用外,Everyting 的值相同External Data Reference
:
ERROR AppDelegate.saveContext():262 - Unresolved error Error Domain=NSCocoaErrorDomain Code=133020 "Impossible de fusionner les changements." UserInfo={conflictList=(
"NSMergeConflict (0x600002c62f40) for NSManagedObject (0x60000158da40) with objectID '0x816659a4c358c32f <x-coredata://CEAE3B14-5782-4C18-AAE8-B05D91CFEC8A/Aquarium/p5>' with oldVersion = 56 and newVersion = 57 and old object snapshot = {\n albums = \"<null>\";\n aquaID = 6;\n dateDeCreation = \"2022-01-15 18:24:00 +0000\";\n imageData = External Data Reference: <self = 0x60000158db80 ; path = 1B9355A6-4101-479D-81F1-DFC106BBCD75 ; length = 1617016>;\n nom = 11321;\n volume = 60;\n} and new cached row = {\n albums = \"<null>\";\n aquaID = 6;\n dateDeCreation = \"2022-01-15 18:24:00 +0000\";\n imageData = External Data Reference: <self = 0x6000015ccf50 ; path = 1B9355A6-4101-479D-81F1-DFC106BBCD75 ; length = 1617016>;\n nom = 11321;\n volume = 60;\n}"
), NSExceptionOmitCallstacks=true}, ["NSExceptionOmitCallstacks": 1, "conflictList": <__NSArrayM 0x600003a25ec0>(
NSMergeConflict (0x600002c62f40) for NSManagedObject (0x60000158da40) with objectID '0x816659a4c358c32f <x-coredata://CEAE3B14-5782-4C18-AAE8-B05D91CFEC8A/Aquarium/p5>' with oldVersion = 56 and newVersion = 57 and old object snapshot = {
albums = "<null>";
aquaID = 6;
dateDeCreation = "2022-01-15 18:24:00 +0000";
imageData = External Data Reference: <self = 0x60000158db80 ; path = 1B9355A6-4101-479D-81F1-DFC106BBCD75 ; length = 1617016>;
nom = 11321;
volume = 60;
} and new cached row = {
albums = "<null>";
aquaID = 6;
dateDeCreation = "2022-01-15 18:24:00 +0000";
imageData = External Data Reference: <self = 0x6000015ccf50 ; path = 1B9355A6-4101-479D-81F1-DFC106BBCD75 ; length = 1617016>;
nom = 11321;
volume = 60;
}
我怀疑数据引用在应用程序加载和我第一次调用备份之间发生了变化。但是长度是一样的,因为这个值在用户端没有改变,所以我不明白为什么引用会改变。
我现在不使用合并策略,它只是不保存。
我可以使用 NSMergeByPropertyObjectTrumpMergePolicy 来确保安全,还是应该找出引用更改的原因?