[swift-evolution] [Proposal] Swift 2.2: #if swift language version

Radosław Pietruszewski radexpl at gmail.com
Fri Dec 18 14:25:11 CST 2015


Sounds like it could be super useful for libraries!

How about we drop the quote marks, though? If we have `os(iOS)` and `#available(iOS 9, *)` (in other context), why not `swift(2.2)`?

— Radek

> On 18 Dec 2015, at 21:22, David Farler via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Hello everyone,
> 
> For Swift 2.2, I'd like to add the following build configuration to check for the Swift language version. This is meant to be a short proposal, so let's start with a simple example, compiling with the 2.2 compiler:
> 
> #if swift("2.2")
>  print("Hello")
> #else
>  this code will not parse or emit diagnostics
> #endif
> 
> The semantics of the build configuration is, "is the Swift language version at least X?". If it is, the active block is parsed and compiled into your program. Like the other build configuration blocks, this isn't line-based, but break on whole statements and declarations. Unlike the other build configurations, however, the inactive block will not parse or emit syntax errors, so you can include syntax for older Swift language revisions in the same file if you prefer.
> 
> It sounds like a lot of folks have been wanting something like this, which is why I'm suggesting it for the Swift 2.2 release. I'm curious to hear your feedback!
> 
> Best,
> David
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list