views:

35

answers:

2

How can I have Xcode warn me if an IBOutlet of one of my objects is not hooked up to anything in a NIB?

I can check that outlets are connected at runtime by adding assert(ofEveryOutlet); in awakeFromNib or viewDidLoad. But it's not as useful, or reliable, as having the compiler do the checking for me.

A: 

The (compiled) NIB files are loaded and connected at runtime, so I don't think there is a way for the compiler to check this. I think your best bet is the asserts you've already suggested...

calmh
+2  A: 

Why not create a Unit Test target that checks your IB bindings and make your application depend on it. That way it will get checked each time you build. See http://blog.carbonfive.com/2010/03/testing/testing-view-controllers for an example of this approach

kharrison
That has the nice property of failing earlier at compile time. Unfortunately it's (generally) a bit more work than assert(), and I *still* have to remember to update the unit tests when I add an IBOutlet. So in my estimation it's a wash
Vincent Gable