Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

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