Last active
April 7, 2021 05:46
-
-
Save DavidPiper94/b1cd1efc43d6734562c9274577519937 to your computer and use it in GitHub Desktop.
Example code for article about UndoManager - Managing a History Part 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class HistoryService { | |
| // ... | |
| // 4 | |
| func registerUndoFor(command: Command) { | |
| undoManager.registerUndo(withTarget: self) { selfTarget in | |
| command.isUndone = true | |
| command.reverse() | |
| selfTarget.registerRedoFor(command: command) | |
| } | |
| } | |
| // 5 | |
| func registerRedoFor(command: Command) { | |
| undoManager.registerUndo(withTarget: self) { selfTarget in | |
| command.isUndone = false | |
| command.execute() | |
| selfTarget.registerUndoFor(command: command) | |
| } | |
| } | |
| // ... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment