NSMergeConflict on iOS7

后端 未结 6 1928
时光取名叫无心
时光取名叫无心 2021-02-06 01:29

I have updated my app to support iOS 7 and have been faced with the problem that on one of screens in my [context save]; I get the following error:

         


        
6条回答
  •  我在风中等你
    2021-02-06 01:58

    I didn't want to mask a potential problem by setting a merge policy without understanding what was causing the NSMergeConflict first.

    In my situation I had performed a NSBatchDeleteRequest earlier on in my code. The NSBatchDeleteRequest is performed directly on the persistent store coordinator so the ManagedObjectContext was unaware of the deletions and still held references to deleted objects. When I later referenced one of these objects and tried to save the context, the NSMergeConflict was thrown.

    Calling reset() on my moc after performing the deletion fixed the issue.

    let fetchRequest = NSFetchRequest(entityName: "Tasks")
    let batchDeleteRequest = NSBatchDeleteRequest(fetchRequest: fetchRequest)
    try managedContext.execute(batchDeleteRequest)
    managedContext.reset() 
    

提交回复
热议问题