Skip to content

Instantly share code, notes, and snippets.

@DavidPiper94
Last active April 7, 2021 05:47
Show Gist options
  • Select an option

  • Save DavidPiper94/d9d903ab21dad30320446e1fbd6ed142 to your computer and use it in GitHub Desktop.

Select an option

Save DavidPiper94/d9d903ab21dad30320446e1fbd6ed142 to your computer and use it in GitHub Desktop.
Example code for article about UndoManager - Managing a History
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