Tag: conditional compilation
Conditional Compilation for iPhone
by Warlock on Jun.17, 2009, under Cocoa, iPhone
I’m working on a view right now that I want to be able to cross compile as either an NSView for the Mac, or a UIVIew for the iPhone. I originally wrote it for Leopard, but now I’m trying to add the precompiler directives to let it cross compile between the two platforms. A quick Google search didn’t reveal anything, here are the possible definitions you can use:
#define __MAC_10_0 1000 #define __MAC_10_1 1010 #define __MAC_10_2 1020 #define __MAC_10_3 1030 #define __MAC_10_4 1040 #define __MAC_10_5 1050 #define __MAC_10_6 1060 #define __MAC_NA 9999 /* not available */ #define __IPHONE_2_0 20000 #define __IPHONE_2_1 20100 #define __IPHONE_2_2 20200 #define __IPHONE_3_0 30000 #define __IPHONE_NA 99999 /* not available */
This definition comes from Availability.h located at /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/usr/include/Availability.h (for the iPhone 3.0 SDK).
Obviously, the __MAC_10_x is actually for the version of OSX, and the __IPHONE_x_x is for iPhone.
So, if you wanted to have code conditionally compile for the iPhone (assuming 3.0 SDK) you would do something like the following:
#ifdef __IPHONE_3_0
// iPhone
#import <UIKit/UIKit.h>
#else
// Mac
#import <Cocoa/Cocoa.h>
#endif