April 2015
Intermediate to advanced
556 pages
17h 47m
English
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, ...