Description
Motivation
The @available
enables warnings and deprecation of functionality based on OS version. This is currently not implemented on Windows:
@available(Windows, introduced: 10.0.17763)
func foo() {}
foo()
main.swift:4:1: error: 'foo()' is only available in * 10.0.17763 or newer
2 │ func foo() {}
3 │
4 │ foo()
│ ├─ error: 'foo()' is only available in * 10.0.17763 or newer
│ ╰─ note: add 'if #available' version check
(I am building against a version of windows greater than this number. The issue also happens when specifying version 1.0.0
or any other value)
Proposed solution
Windows has well defined version numbers of the form 10.0.<buildnumber>
as described on Wikipedia: https://en.wikipedia.org/wiki/Windows_10_version_history . This scheme also supports version numbers prior and subsequent to Windows 10.
On Windows, @available
should test whether the Windows version we're building for is greater or equal to the specified version number. As a first approximation, this could use the version number of the Windows SDK we're building for (-windows-sdk-version
), but ideally we could also specify a target version number separately. The if #available
syntax should also be supported on Windows.
Alternatives considered
As a workaround, it's possible to do runtime checks.
Additional information
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Status