Now that Swift is ABI stable, I'm worried the community will run into the same problem iOS developers have had to face for years. Namely, when Apple would release a fancy new feature at WWDC, we would need to wait for some time before using it because most of the time (and per Apple's own recommendation) we were targeting the last two releases of iOS and the previous release did not contain said fancy new feature!
Let me illustrate with a specific example:
Ordered collection diffing is landing in
5.1. We write some code using this new feature, but when we compile targeting an older version of iOS, which provides its own older version of Swift, we get an errorr that
'difference(from:)' is only available on OS X 9999 or newer (that OS X 9999 thing is what the current toolchain displays, and in reality it would likely say something like
Swift has one advantage here, in that it is open source, so the enterprising developer can go ahead and copy that method from the standard library and encase it in a
#if swift(<5.1), but this feels a little heavyweight and may cause some unexpected behavior if the behavior diverges between Swift versions or if they make a mistake like grabbing the file at the wrong commit version.
It would be great if there was a mechanism to do this automatically. For instance a
@embeddableSince(5.0) attribute which would, when targeting Swift 5.0, simply embed the functionality in the resulting binary.
Is there an existing mechanism would better address this issue? Am I missing something that makes this not a problem? Any feedback is greatly appreciated!