Skip to content

Browser version support in platform checks #1766

Open
@MaxDesiatov

Description

@MaxDesiatov

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions