Compiling code only for the iOS 8.1 SDK in Swift -
Compiling code only for the iOS 8.1 SDK in Swift -
i want conditionally compile code when building ios 8.1 sdk, , compile different code when using 8.0 sdk. in little project targets 8.1 sdk (and can utilize apis new 8.1), appears #if directive ignores constants.
println("__iphone_8_1 defined \(__iphone_8_1)") #if __iphone_8_1 println("8.1") #else println("8.0") #endif the above code prints:
__iphone_8_1 defined 80100 8.0 according documentation on conditional compilation statements,
swift code can conditionally compiled based on evaluation of build configurations. build configurations include literal true , false values, command line flags, , platform-testing functions listed in table below. can specify command line flags using -d <#flag#>.
it talks os() , arch() functions has nil sdk versions.
currently swift not back upwards referencing constants conditional compilation predicates. solution specific case define different compiler flags depending on sdk version.
under xcode's build settings, go other swift flags can set flags different sdks. since xcode installation not associated both 8.0 , 8.1 sdks, edited project.pbxproj file hand:
"other_swift_flags[sdk=iphoneos8.1]" = "-d debug -d __iphone_8_1"; "other_swift_flags[sdk=iphoneos8.0]" = "-d debug"; in xcode looks like:
ios swift ios8 ios8.1
Comments
Post a Comment