Key Value Coding 6: A Longer Key Path

KVO6 adds two more ivars for two more vehicles. You can download the code here.
KVO6-1
Most of the changes are under the hood. Instead of using an NSDictionary like KVO5 did, KVO6 uses a custom container class called VehicleCollection. VehicleCollection looks like this:
KVO6-2
It has two ivars cars and bikes, each storing Vehicles. This adds an extra level of selection to the key path. Notice that the VehicleCollection has no accessors. The -init code looks like this:
KVO6-3
Notice that to set up the vehicles it uses setValue:forKey: on the Vehicle class. That's because the Vehicle class doesn't have any accessors to use. This brings up another useful aspect of using KVC: KVC does the release/retain for you. When setValue is used, it takes care of the reference counting automatically, releasing the old object and retaining the new one. Less code to write, debug, and maintain.

The application controller uses an ivar called mytoys to store a pointer to a VehicleCollection:
KVO6-4
Now comes the interesting part, accessing the ivars of the Vehicles inside the VehicleCollection. AppController does it this way:
KVO6-5
The key path now has three parts. If the user types "paint", then the first ivar access is to cars.suv.paint. This accesses the cars ivar of the mytoys vehicle collection, then the NSDictionary of the VehicleCollection to find the suv object, then the paint ivar of the Vehicle object. All with no accessors. There is no limit to the length of key paths.
The Bagelturf site welcomes Donations of any size