RXObjectBinder
(Kiss some glue code goodbye!)
Ever since I started using bindings, and especially since their momentum has kept growing, I've wanted something like an NSObjectController turned backwards. How so?
NSObjectController instances let you bind to their target object's properties. For example, if you have an instance of a custom class, controls can bind to an NSObjectController instance representing it, and thus display (and control) specifics of its state without writing glue code.
What if your custom class is a view class, though? What if you have a view in a collection view that you want to make represent the individual items that the collection view is displaying? You can't bind your view's properties as-is, because it isn't instantiated by Interface Builder (and thus its -exposedBindings method won't be called). What do you do?
You either
- manually bind the view to the collection view item in your window controller (or some other responsible controller class), presumably adding outlets and a few lines to your
-awakeFromNibimplementation, or - hack up an IB3 plugin to instantiate your view and its bindings
I want this sort of thing all the time. It drives me nuts that NSObjectController won't let me do it. So I wrote RXObjectBinder, which will. Here's how it works:
- Instantiate
RXObjectBinder(it's the red hypercube seen up top) - Connect its
representedObjectoutlet to the appropriate object (probably most frequently a view) - On its Attributes inspector, add the keys that you'd like to bind.
- On its Bindings inspector, bind them.
You'll obviously also have to either link against RXObjectBinderFramework (annoying) or just compile the RXObjectBinder class in (not as annoying). I'd recommend the latter.
At runtime, the bindings are forwarded directly to the representedObject, so there shouldn't be any bizarre proxying screw-ups here (10.4-era NSTreeController, anyone?). In practice I'm finding this to be very pleasant, and not nearly as much of an unholy hack as I feared it would be. It's entirely documented-API, blessed-methods-of-InterfaceBuilderKit—kosher, in fact—and quite minimalistic.
In short, I like it, and I hope you will too. Download away, or if you have git feel free to get the source directly:
git clone git://github.com/robrix/objectbinder.git
Feel free to submit patches to me.
It's BSD licensed, natch, and your nibs should deploy just fine to both 10.4 and 10.5. (Only 10.5 has been tested so far.) If you want to edit your RXObjectBinder-bearing nibs under 10.4/IB2 then I can't help you—perhaps no one can.