Created
April 7, 2021 05:46
-
-
Save DavidPiper94/cfc31ba02100d3aa46495cbcff02476a to your computer and use it in GitHub Desktop.
Example code for article about UndoManager - Managing a History Part 3
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 { | |
| // ... | |
| // 6 | |
| func record(command: Command) { | |
| // Remove all undone actions at top of list. | |
| history = Array(history.drop { $0.isUndone} ) | |
| // Prepend command. | |
| history = [command] + history | |
| registerUndoFor(command: command) | |
| // Execute command. | |
| command.execute() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment