Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

[Cocoa] Low verbosity Cocoa and KVO

branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time


by Joachim Bengtsson

In my quest to write the most succinct, short and readable code humanly possible, I've written a few tools to help me. These tools are elaborately described on my blog, but in short:


Defines macros for creating your standard containers and "POD" objects (NSNumber, NSString, ...). I've always had such a file copy-pasted between projects, but this particular iteration is very much inspired by the excellent Jens Alfke's CollectionUtils, plus some ARC fixes and fixes. Unsung heroes: $castIf, $notNull.


A KVO observation needs to be registered and deregistered at the right points. You have this as a concept, but you have no object representing this concept. That sucks. SPKVONotificationCenter gives you an object to represent the concept of a KVO observation that you can manage like any other object; and the world is a nice place to live again.


On top of that, SPDepends experiments with magic, letting you subscribe to say three different KVC key paths on two different objects and getting a callback when anything changes, all in a line or two:

$depends(@"alarm", lock, @"locked", sensor, @"adjacentPeople", @"isOn", self, @"isOn", ^{
  if(lock.locked && sensor.adjacentPeople.count > 0 && sensor.isOn && selff.isOn)
    [selff triggerAlarm];

I find that this really brings out the power in KVO in a way only Bindings have done previously.

Something went wrong with that request. Please try again.