Skip to content

Document a pattern to replace @available (Obj-C) / #available (Swift) #1588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
stuartmorgan-g opened this issue Sep 23, 2024 · 3 comments
Open
Labels
lang-objective_c Related to Objective C support package:ffigen

Comments

@stuartmorgan-g
Copy link

iOS/macOS development has a common pattern where an SDK introduces a new preferred API and deprecates the old API at the same time. In the old days this was a pretty painful experience for developers, but at some point Apple introduced the available system to make it much simpler and safer.

Main features:

  1. If you unconditionally call an API that's available on OS version N, but your minimum deployment target is <N, you get a development-time warning.
  2. If you correctly wrap that call in an available check, that warning goes away, and then you automatically have the logic to do whatever runtime conditional is necessary (usually calling the now-deprecated API in the else).

#300 covers throwing instead of crashing, but doesn't solve the problem that available and the associated warnings does, which is making it very easy to handle iOS version differences correctly, and very hard to accidentally fail to do so.

We should have a recommended pattern for doing the runtime check, and clearly document it somewhere as how to handle APIs that aren't available on newer OS versions. But if it's just an OS version check, that will still be significantly more error-prone than available because developers will be responsible for looking up every single API they are using to check its availability. If we want to replicate the same level of safety and ease of use that available provides, we would need to propagate version annotations through into the generated code in some way, somehow make the Dart analyzer aware of min native deployment version, and create new lints that replicate the warnings for missing checks.

@stuartmorgan-g
Copy link
Author

Cross-reference: #1590 which is a similar issue on Android.

@liamappelbe
Copy link
Contributor

Related: #1338. If you set a minimum target version, then ffigen won't generate bindigns for APIs that were deprecated before that version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang-objective_c Related to Objective C support package:ffigen
Projects
Status: Todo
Development

No branches or pull requests

4 participants