Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preprocessor macro to target Interface Builder not available to OS X?

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.

like image 577
Ben Stock Avatar asked Nov 15 '14 14:11

Ben Stock


1 Answers

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
like image 65
Tamás Zahola Avatar answered Sep 29 '22 12:09

Tamás Zahola