R – Guidelines for creating non-view objects in a XIB file

interface-builderiphonenibxib

Interface Builder provides the ability to create non-view/controller objects in a XIB file. In the past I have used this feature to instantiate and wire-up small components that manage view components in the XIB and this seemed a fairly reasonable thing to do.

However, I was wondering what other legitimate uses there are for this feature. It is rather attractive tool as it effectively moves the responsibility for instantiating and injecting the dependencies of such objects out of your code and onto the framework.

In the case of Interface Builder I am curious to know what the guidelines are for using this dependency injection feature?

Best Answer

The rule of thumb I use, is auxiliary objects can be put in if they are related to the UI being defined in the nib in some way - so either proxy objects that hold references to elements or actions that get triggered.

Proxy methods all get wired in when loading the nib and pass in the already created object via the userinfo dictionary you can optionally pass in along with the nib name.

There's nothing at all wrong though I think, in a purely logical nib that would use the target/action system to wire up multiple proxy objects. That might be easier than doing all the wiring in code, though I've not seen that used in practice.

Related Topic