I have an IB_DESIGNABLE
custom NSView
subclass. When drawing, I want my view to perform a method only when it's being run in Interface Builder. I looked this up, and Apple's documentation states:
You can use the preprocessor macro
TARGET_INTERFACE_BUILDER
to specify code for inclusion with or exclusion from your custom view class.- (void)connectToMyServer { #if !TARGET_INTERFACE_BUILDER // connect to the server #else // don't connect; instead, draw my custom view #endif }
I jumped over to my code, and added the following to one of my methods:
#if TARGET_INTERFACE_BUILDER
[self myMethodForInterfaceBuilder];
#endif
Immediately, I got the following error:
... /MyCustomView.m:134:8: Use of undeclared identifier 'TARGET_INTERFACE_BUILDER'
This leads me to believe that the TARGET_INTERFACE_BUILDER
preprocessor macro is only good for Xcode targets using the iOS SDK. Am I correct in this assumption, or have I overlooked something? Any advice would be great! Thanks.
That macro is only defined when Interface Builder is building your code. Therefore the correct usage is this:
#ifdef TARGET_INTERFACE_BUILDER
... // for Interface Builder
#else
... // regular behavior
#endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With