Undoing changes #17

Closed
opened 2025-12-29 15:22:07 +01:00 by adam · 6 comments
Owner

Originally created by @yoiang on GitHub (Nov 4, 2015).

Hey @JohnEstropia !
I've just started using CoreStore and I'm excited!

I was wondering, are there were any plans to expose some sort of undo functionality similar to or using the NSUndoManager? Or can something similar be achieved already with Unsafe Transactions?

Thanks!

Originally created by @yoiang on GitHub (Nov 4, 2015). Hey @JohnEstropia ! I've just started using CoreStore and I'm excited! I was wondering, are there were any plans to expose some sort of undo functionality similar to or using the NSUndoManager? Or can something similar be achieved already with Unsafe Transactions? Thanks!
adam closed this issue 2025-12-29 15:22:08 +01:00
Author
Owner

@JohnEstropia commented on GitHub (Nov 5, 2015):

@yoiang Thanks for the feedback!
If I remember correctly, the undoManager for all transactions should be intact, but direct access to the NSManagedObjectContext is currently not allowed on async and sync transactions. You are right that you can invoke undo operations on the UnsafeDataTransaction though!

let transaction = CoreStore.beginUnsafe()
// .. do some things
transaction.internalContext.undo()

Can you share your use-case for needing undo operations? If I find enough demand for it I might enable it on all transaction classes as well.

@JohnEstropia commented on GitHub (Nov 5, 2015): @yoiang Thanks for the feedback! If I remember correctly, the `undoManager` for all transactions should be intact, but direct access to the `NSManagedObjectContext` is currently not allowed on async and sync transactions. You are right that you can invoke undo operations on the `UnsafeDataTransaction` though! ``` swift let transaction = CoreStore.beginUnsafe() // .. do some things transaction.internalContext.undo() ``` Can you share your use-case for needing undo operations? If I find enough demand for it I might enable it on all transaction classes as well.
Author
Owner

@yoiang commented on GitHub (Nov 13, 2015):

Hey @JohnEstropia ! Sorry for the late response.

A use case I run into a fair bit is a View that visualizes a Model of some kind and let's say we provide a View and an Edit mode, during the life of the View the user may edit changes to the Model, press Cancel and undo all changes or undo particular changes, or press Done and have the changes committed.

Lemme know if I could be more specific or provide any more info.

@yoiang commented on GitHub (Nov 13, 2015): Hey @JohnEstropia ! Sorry for the late response. A use case I run into a fair bit is a View that visualizes a Model of some kind and let's say we provide a View and an Edit mode, during the life of the View the user may edit changes to the Model, press Cancel and undo all changes or undo particular changes, or press Done and have the changes committed. Lemme know if I could be more specific or provide any more info.
Author
Owner

@JohnEstropia commented on GitHub (Nov 14, 2015):

@yoiang
Okay, I think UnsafeDataTransactions fits well for such cases. You should be able to implement this right now, but I'll add some utility methods to the transactions so we can save some typing :)

@JohnEstropia commented on GitHub (Nov 14, 2015): @yoiang Okay, I think `UnsafeDataTransaction`s fits well for such cases. You should be able to implement this right now, but I'll add some utility methods to the transactions so we can save some typing :)
Author
Owner

@JohnEstropia commented on GitHub (Nov 14, 2015):

@yoiang
Sorry, I just realized that the default NSUndoManager in iOS is nil, so you may need to create one and assign it to transaction.internalContext.undoManager. Another method is to recreate a new transaction with beginUnsafe() every time the user tries to undo all changes.

@JohnEstropia commented on GitHub (Nov 14, 2015): @yoiang Sorry, I just realized that the default `NSUndoManager` in iOS is `nil`, so you may need to create one and assign it to `transaction.internalContext.undoManager`. Another method is to recreate a new transaction with `beginUnsafe()` every time the user tries to undo all changes.
Author
Owner

@yoiang commented on GitHub (Nov 14, 2015):

@JohnEstropia
Sounds good! If I notice a pattern with doing undo work with CoreStore that fits the CoreStore styling would you mind if I suggested a PR?

@yoiang commented on GitHub (Nov 14, 2015): @JohnEstropia Sounds good! If I notice a pattern with doing undo work with CoreStore that fits the CoreStore styling would you mind if I suggested a PR?
Author
Owner

@JohnEstropia commented on GitHub (Nov 14, 2015):

@yoiang

Sounds good! If I notice a pattern with doing undo work with CoreStore that fits the CoreStore styling would you mind if I suggested a PR?

I'd appreciate that! :)

@JohnEstropia commented on GitHub (Nov 14, 2015): @yoiang > Sounds good! If I notice a pattern with doing undo work with CoreStore that fits the CoreStore styling would you mind if I suggested a PR? I'd appreciate that! :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#17