我只在一个线程上运行coredata。基本上我有一个消息传递应用程序,我试图批量删除消息...所以这工作..但一旦我开始再次发送消息...我得到此错误
这是我用来删除邮件的内容:
let fetchRequest = NSFetchRequest(entityName: "Mesages")
fetchRequest.predicate = NSPredicate(format: "user.id = %@", friendID)
let batchDeleteRequest = NSBatchDeleteRequest(fetchRequest: fetchRequest)
do {
try context.executeRequest(batchDeleteRequest)
context.refreshAllObjects()
} catch {}
错误域= NSCocoaErrorDomain代码= 133020“(null)”UserInfo = {conflictList =( “NSMergeConflict(0x610000264140)for NSManagedObject(0x6080000ae520)with objectID'0xd000000006640002'with oldVersion = 1 and newVersion = and old object snapshot = {\ n fromID = 300147143696943; \ n isSender = 0; \ n status = \”\“; \ n text = Ggg; \ n timestamp = \“2016-09-18 02:13:30 +0000 \”; \ n toID = \“\”; \ n user = \“0xd000000000640000 \”; \ n}“, “NSMergeConflict(0x610000265ac0)for NSManagedObject(0x6000000adb60)with objectID'0xd000000006600002'with oldVersion = 2 and newVersion = and old object snapshot = {\ n fromID = 300147143696943; \ n isSender = 0; \ n status = \”\“; \ n text = Gg; \ n timestamp = \“2016-09-18 02:09:41 +0000 \”; \ n toID = \“\”; \ n user = \“0xd000000000640000 \”; \ n}“ )}
我不知道发生了什么事,有人可以帮忙
答案 0 :(得分:0)
也许您应该在save()之前设置persistentContainer(NSPersistentCloudKitContainer)的viewContext的mergePolicy,这样编写:
yourContext.mergePolicy = NSMergeByPropertyStoreTrumpMergePolicy
OR
yourContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy