Cross-Platform Development

Other topics

TargetConditionals

The system header TargetConditionals.h defines several macros which you can use from C and Objective-C to determine which platform you're using.

#import <TargetConditionals.h>  // imported automatically with Foundation

- (void)doSomethingPlatformSpecific {
#if TARGET_OS_IOS
    // code that is compiled for iPhone / iPhone Simulator
#elif TARGET_OS_MAC && !TARGET_OS_IPHONE
    // code that is compiled for OS X only
#else
    // code that is compiled for other platforms
#endif
}

The values of the macros are:

7.0

When using the iOS 9.1, tvOS 9.0, watchOS 2.0, OS X 10.11 or newer SDKs:

MacroMaciOSiOS simulatorWatchWatch simulatorTVTV simulator
TARGET_OS_MAC1111111
TARGET_OS_IPHONE0111111
TARGET_OS_IOS0110000
TARGET_OS_WATCH0001100
TARGET_OS_TV0000011
TARGET_OS_SIMULATOR0010101
TARGET_OS_EMBEDDED0101010
TARGET_IPHONE_SIMULATOR0010101
7.0

When using the iOS 8.4, OS X 10.10, or older SDKs:

MacroMaciOSiOS simulator
TARGET_OS_MAC111
TARGET_OS_IPHONE011
TARGET_OS_EMBEDDED010
TARGET_IPHONE_SIMULATOR001

Contributors

Topic Id: 358

Example Ids: 1219

This site is not affiliated with any of the contributors.