Key Value Coding 10: Do Some Math

KVO10 adds another ivar and some math to the mix. Download the code and see how KVC can do math for you.
KVO10-1
There are the five ivar text fields that were there previously, but now five more are added that do math on the other fields. Doing this used no code, just key paths. AppController implements the functionality like this:
KVO10-2
To calculate the sum a key path with a special @sum element is used. So in the example above, the key path is collection.@sum.passengers. That means to get the array referenced by collection and apply the passengers message to each element, then sum the returned values. So this gets the sum of passengers for all the vehicles in the collection.

The other fields work the same way. The only odd one is the count of values. That one uses the key path collection.@count and does not need an ivar name to do its work since it is just counting array elements.

So far I have shown KVO doing the work of accessors, storage management, and math. Saving code, errors, and maintenance. Key paths do more than that, but a visit will be postponed until some other things have been covered.
The Bagelturf site welcomes Donations of any size