Compiling code only for iOS 8.1 SDK in Swift

I want to conditionally compile some code when creating using the iOS 8.1 SDK and compile some other code when using the SDK 8.0. In a small project that targets SDK 8.1 (and can use the new APIs for 8.1), the directive appears to #ifignore constants.

println("__IPHONE_8_1 is defined to be \(__IPHONE_8_1)")
#if __IPHONE_8_1
    println("8.1")
    #else
    println("8.0")
#endif

The above code prints:

__IPHONE_8_1 is defined to be 80100
8.0

According to the documentation for conditional compilation operators ,

Swift code can be conditionally compiled based on the assessment of build configurations. Build configurations include literal trueand false, command line flags, and platform testing features listed in the table below. You can specify command line flags with -D <#flag#>.

os() arch(), SDK.

+4
1

Swift . SDK.

Xcode Other Swift Flags, SDK. Xcode SDK 8.0 8.1, project.pbxproj:

"OTHER_SWIFT_FLAGS[sdk=iphoneos8.1]" = "-D DEBUG -D __IPHONE_8_1";
"OTHER_SWIFT_FLAGS[sdk=iphoneos8.0]" = "-D DEBUG";

Xcode :

L5Aww.png

0

All Articles