I have a Swift demo project that comes with my map. I want to make sure that the Swift code in the demo successfully compiles with both Xcode 6 (Swift 1.2) and Xcode 7 (Swift 2.0) without user intervention .
Since there is only marginal preprocessor support in Swift , how can I determine at compile time which version of Swift or Xcode is used to compile the code?
Now here is the important detail:
- It should work automatically!
- Open a project in Xcode 6 -> compiles Swift 1.2 code.
- Open project in Xcode 7 -> compiles Swift 2.0.
There are no build settings or other tools that require the user to specify, anyway, which version of Swift / Xcode it uses.
I keep thinking: this is such a trivial task, how could this be impossible with Swift?
As a framework developer, this infuriates me, since the successful compilation of the Swift project now completely depends on the user version of Xcode, and I cannot ask them to “upgrade to Xcode 6.4” and at a later point ask them to “upgrade to Xcode 7.1 again”. This is madness!
An alternative would, of course, be to have separate demo projects managing different code bases, one for each version of Swift. And hoping that the user will find out which project will work with its version of Xcode. Not a real alternative.
Another alternative that simply does not use any Swift 2.0 enhancement, unfortunately, is not possible either. There is syntax, classes, and methods that will not work in a particular version of Swift, if only because the compiler becomes more picky in newer versions of Xcode.
source share