Xcode
Cross-platform ontwikkeling
Zoeken…
TargetConditionals
De systeemkop TargetConditionals.h
definieert verschillende macro's die u kunt gebruiken vanuit C en Objective-C om te bepalen welk platform u gebruikt.
#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
}
De waarden van de macro's zijn:
7.0
Bij gebruik van iOS 9.1, tvOS 9.0, watchOS 2.0, OS X 10.11 of nieuwere SDK's:
macro | Mac | iOS | iOS-simulator | Kijk maar | Bekijk simulator | TV | TV simulator |
---|---|---|---|---|---|---|---|
TARGET_OS_MAC | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
TARGET_OS_IPHONE | 0 | 1 | 1 | 1 | 1 | 1 | 1 |
TARGET_OS_IOS | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
TARGET_OS_WATCH | 0 | 0 | 0 | 1 | 1 | 0 | 0 |
TARGET_OS_TV | 0 | 0 | 0 | 0 | 0 | 1 | 1 |
TARGET_OS_SIMULATOR | 0 | 0 | 1 | 0 | 1 | 0 | 1 |
TARGET_OS_EMBEDDED | 0 | 1 | 0 | 1 | 0 | 1 | 0 |
TARGET_IPHONE_SIMULATOR | 0 | 0 | 1 | 0 | 1 | 0 | 1 |
7.0
Bij gebruik van de iOS 8.4, OS X 10.10 of oudere SDK's:
macro | Mac | iOS | iOS-simulator |
---|---|---|---|
TARGET_OS_MAC | 1 | 1 | 1 |
TARGET_OS_IPHONE | 0 | 1 | 1 |
TARGET_OS_EMBEDDED | 0 | 1 | 0 |
TARGET_IPHONE_SIMULATOR | 0 | 0 | 1 |
Modified text is an extract of the original Stack Overflow Documentation
Licentie onder CC BY-SA 3.0
Niet aangesloten bij Stack Overflow