I'm writing to report an issue our team has encountered with the Swift API that is causing compatibility problems. We're eager to enable our users to enjoy new APIs, but we've run into a bug with the available function.
I'm using Xcode 14.3 (14E222b) - Swift 5.8 (swiftlang-188.8.131.52.2 clang-1403.0.22.11.100) on a MacBook Pro M1.
The included example below illustrates the issue. We expected that ifGen16 would not raise the error('tint' is only available in iOS 16.0 or newer) since it has passed in the function.
We've filed feedback (FB12160860), but I wanted to reach out to the community for guidance and advice. Do you have any ideas on how we can work around this and keep a clean API, or do we need to copy-paste the code below everywhere?
A possible solution to this issue would be to disable warnings about availability, as I am certain that it is checked and valid. However, in Swift, we do not have a way to disable certain warnings or errors, which can block us when faced with situations like the one described above. It would be great if the Swift team could consider adding a way to programmatically disable errors or warnings, for instance by using special comments.
disablingError takes an error name and the line number when the error should be disabled.
Ah right, the availability checks aren't parameter attributes, so the compiler has no way of knowing that closure is only called in iOS 16 contexts. Such an API isn't really possible right now so most people create direct wrappers for the conditional API they need. In your example you'd create a tint modifier that is essentially your ifGen16 conditional under the hood, but only for the tint call. Hopefully we'll see some better solutions here with the new @backDeploy attribute in Swift 5.9.