Undo for Edits
It is time now for you to add undo support for editing of employees’s fields to RaiseMan. The first step is to register Document to observe changes to the Employee objects in its employees array. Add the following private variable near the top of Document.swift:
import Cocoa private var KVOContext: Int = 0 class Document: NSDocument {
You will use the KVOContext variable to get a unique value to use as the KVO context pointer.
Next, add this section inside the Document implementation:
// MARK: - Key Value Observing func startObservingEmployee(employee: Employee) { employee.addObserver(self, forKeyPath: "name", options: .Old, context: &KVOContext) employee.addObserver(self, forKeyPath: "raise", options: .Old, ...
Get Cocoa Programming for OS X: The Big Nerd Ranch Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.