Hi, all. Swift 4.1 is off on its own branch and going well, but we never quite 
came up with an answer for a particular problem developers might have: "am I 
running a Swift 4.1 compiler?".

#if swift(>=3.2)
// Swift 3.2 (4.0 in compatibility mode)
// Swift 3.3 (4.1 in compatibility mode)
// Swift 4.0
// Swift 4.1
#endif

#if swift(>=3.3)
// Swift 3.3 (4.1 compatibily mode)
// Swift 4.0
// Swift 4.1
// this one is probably not very useful
#endif

#if swift(>=4.0)
// Swift 4.0
// Swift 4.1
#endif

#if ???
// Swift 3.3
// Swift 4.1
#endif

I don't think this is going to come up a lot, but given that we do have changes 
to the standard library and to the language, I can see people wanting it. Right 
now the only way to do it is the rather unwieldy:

#if swift(>=4.1) || (swift(>=3.3) && !swift(>=4.0))
print("new")
#else
print("old")
#endif

Do we need something better here, or do you think people will be okay with 
this? I'm realizing I don't really know how many people try to keep their 
libraries working across Swift versions and run into compatibility issues. 

(Strictly speaking this problem is already present with Swift 4.0.2 with 3.2.2 
compatibility mode, but that's much less likely to come up.)

Jordan
_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

Reply via email to