Last active
April 7, 2021 05:47
-
-
Save DavidPiper94/d9d903ab21dad30320446e1fbd6ed142 to your computer and use it in GitHub Desktop.
Example code for article about UndoManager - Managing a History
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 { | |
| // 1 | |
| let undoManager = UndoManager() | |
| var history = [Command]() | |
| // 2 | |
| var canUndo: Bool { undoManager.canUndo } | |
| func undo() { | |
| guard canUndo else { return } | |
| undoManager.undo() | |
| } | |
| // 3 | |
| var canRedo: Bool { undoManager.canRedo } | |
| func redo() { | |
| guard canRedo else { return } | |
| undoManager.redo() | |
| } | |
| // ... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment