Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

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