April 2015
Intermediate to advanced
556 pages
17h 47m
English
Now that you have a general idea of how your code will interact with the undo manager, let’s look at a more concrete example. Suppose that you are writing a thermostat application. It has a property, undoManager, an instance of NSUndoManager, as well as a method, makeItHotter(), whose inverse is makeItColder(). Here is how you would implement undo for it:
func makeItHotter() {
temperature += 10
undoManager.prepareWithInvocationTarget(self).makeItColder()
showTheTemperature()
}
Two steps are performed: the prepareWithInvocationTarget(_:) method is called on the undo manager. It returns an object which you then call makeItColder() on. The return type of prepareWithInvocationTarget(_:) is AnyObject. The object it ...
Read now
Unlock full access