How to get a compiler warning when an IBOutlet is disconnected
-
20-09-2019 - |
Question
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.
Solution
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...
OTHER TIPS
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