Search code examples
swiftxcodeconditional-compilation

ifdef for specific Xcode versions?


I'm currently converting some of my code to compile in Xcode 9 and stumbled over some different behaviour which forces me to use some code only in Xcode 9 and some only in Xcode 8. Is there some kind of ifdef so I can redirect code based on the Xcode version used?

Any help appreciated. Thanks!


Solution

  • There are no conditional compilation preprocessor macros for Xcode versioning. Currently, this is the best you can do:

    #if swift(>=3.2)
        // Xcode 9 
    #else
        // Xcode 8
    #endif
    

    Since Swift 3.2 is available only via Xcode 9 or higher, this should serve your practical needs.

    If you have discovered an Xcode-related bug, file it at Apple's Bug Reporter website here.