April 2015
Intermediate to advanced
556 pages
17h 47m
English
Given that your users are probably going to add cars to the system when they purchase them, it would be nice if the datePurchased attribute were set to the current date. One good way to do this is to subclass NSArrayController and override its newObject() method.
Create a new file of type Cocoa Class. It will be a subclass of NSArrayController. Name it CarArrayController. In CarArrayController.swift, override newObject:
override func newObject() -> AnyObject {
let newObj = super.newObject() as! NSObject
let now = NSDate()
newObj.setValue(now, forKey:"datePurchased")
return newObj
}
Open Document.xib in Interface Builder and select the array controller. In the identity inspector, ...
Read now
Unlock full access