compile CaseIterable in Xcode 9 but not in Xcode 10

Can anybody tell me a clean way to compile a Swift protocol and its implementation in Xcode 9 but not in Xcode 10?


I tried various options, including some based on conditional compilation like #if swift(>=4.2), and currently use a very ugly method based on duplicating the target. I wonder if there isn't any clean way.


The concrete reason is the protocol CaseIterable. I welcome the addition of this protocol to Swift 4.2 in Xcode 10, as it enables iterations over all cases of an enumeration. I look forward to removing my own implementation of that protocol, which was based on the fact that hashValue and rawValue in an enumeration used to return the same thing (described at various places, in this blog for example). This implementation does not work in Xcode 10 anymore, since hashValue has changed. That should not be a problem, I can just use the new compiler-supported implementation of CaseIterable, right? Unfortunately I cannot see a clean way of excluding my implementation of the protocol in Xcode 10 while keeping it for Xcode 9.

Answered by grundoon in 318225022

cp101 – See if checking against (>=4.1.50) helps: vapor/core/pull/160/files at github

(link deconstructed to avoid sitting in moderation queue)


"Swift 4.2 compiler defines

CaseIterable
even if it is compiling in a compatibility mode. This PR uses a hack that the Swift team has given us until the
#compiler
directive is available to determine whether or not we are using the Swift 4.2 compiler in lieu of just checking the version."

Thanks, I'll take this as an official confirmation for grundoon's suggestion.


It certainly make sense that new users adopt CaseIterable as soon as possible. The issue is that the App Store does not accept submissions from Xcode 10 as long at it is in beta mode, so I had to add a compatible version only for Xcode 9. The check on the unexpected Swift version 4.1.50 allows this.

compile CaseIterable in Xcode 9 but not in Xcode 10
 
 
Q