Undoing Core Data insertions that are performed off the main thread

前端 未结 5 2078
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-30 09:41

I\'m working on some code that uses an NSOperation to import data. I\'d like for the user to be able to undo the NSManagedObject instances that are cre

5条回答
  •  死守一世寂寞
    2021-01-30 10:08

    It's incredibly likely you've considered this and you're likely only looking for a solution using the existing undoManager, but just in case:

    Since you're inserting objects and not updating existing ones, you do have the power to tag them with a transaction id as each batch is imported, deleting them in a background thread in the case of an undo. A simple incremented NSNumber is sufficient for the tag.

    Inelegant, but workable.

提交回复
热议问题