合并冲突核心数据

时间:2018-07-08 19:16:11

标签: ios swift core-data

在合并Core Data的策略时需要一些建议...有时我会收到此错误NSMergeConflict for NSManagedObject with ObectID...。我尝试在线搜索,发现我需要在appDelegate中删除我的FatalError方法,并使用了合并策略来解决此类问题。...我阅读了Apple的文档,并需要一些确认。我当前的流程是,我调用一个API,无论返回什么结果,我都将它们保存到CoreData中,然后将其提取并显示在我的tableView上...这些结果首先保存到核心数据中,因为它们将在显示时显示没有互联网。当有互联网时,我删除所有先前的对象,然后重复显示过程。有时我遇到FatalError导致崩溃。我使用哪种合并策略?

  1. mergeByPropertyObjectTrump
  2. mergeByPropertyStoreTrump
  3. 覆盖
  4. 回滚

我得到的错误: Fatal error: Unresolved error Error Domain=NSCocoaErrorDomain Code=133020 "Could not merge changes." UserInfo={conflictList=( "NSMergeConflict (0x115c27ed0) for NSManagedObject (0x109f129b0) with objectID '0xd000000000440000 <x-coredata://4D2070B8-C99C-49F5-A3B5-7E8E360ECA3A/CDPortfolio/p17>' with oldVersion = 1 and newVersion = <deleted> and old object snapshot = {\n currentValue = \"49141.4\";\n folioNo = 12345;\n growthPercentage = \"5109904.532582804\";\n investmentAmount = 5000;\n isExpanded = 0;\n minRedemptionAmount = 500;\n noOfUnits = 100;\n schemeCategory = 54;\n schemeHouse = 97;\n schemeMasterID = 1000390;\n schemeNAV = \"491.414\";\n schemeName = \"HDFC Taxsaver (G)\";\n schemeReturn = \"1:4.1782,2:17.2281,3:10.9636,5:17.9405,7:11.8873,10:13.5671\";\n}", "NSMergeConflict (0x109f1a340) for NSManagedObject (0x109f128e0) with objectID '0xd000000000400000 <x-coredata://4D2070B8-C99C-49F5-A3B5-7E8E360ECA3A/CDPortfolio/p16>' with oldVersion = 1 and newVers

1 个答案:

答案 0 :(得分:1)

合并政策是邪恶的;它要求核心数据删除您的一些数据。通过仅以单次同步方式写入核心数据,最好首先避免写入冲突。有关如何在此处进行设置的完整说明:https://stackoverflow.com/a/42745378/1143046