Open
Description
When writing requirements for swiftwasm/JavaScriptKit#56, it reminded me of my old idea for browser version checks in Swift:
@available(Safari 14, Edge 79, Firefox 68, Chrome 67)
final class JSBigInt {
//...
}
Then user code could look like:
if #available(Safari 14, Edge 79, Firefox 68, Chrome 67) {
// code that uses `JSBigInt`
else {
// backward-compatible code
}
Ideally, one would write:
if #available(JSBigInt) {
// code that uses `JSBigInt`
else {
// backward-compatible code
}
but this doesn't match the existing semantics of #available
, which checks for platforms, not features. And making the toolchain aware of every feature is not realistic in my opinion. Besides, AFAIR Xcode (and hopefully SourceKit-LSP) fix-its propose adding corresponding platform version checks automatically after you attempt to use a "future" API when targeting older platforms.