How do I use @available and availability checks?

The `@available` attribute in Swift is used to indicate the availability of APIs across different versions of iOS, macOS, watchOS, or tvOS. It allows developers to write code that can conditionally execute based on the availability of a feature or API on the current platform version. This ensures that your application can gracefully handle situations where certain functionalities are not available due to version constraints.

Using the availability checks, you can write code that checks if a particular API is available before attempting to use it. This helps avoid runtime crashes and provides a better user experience.

Example of Using @available

if #available(iOS 13, *) { // Use a feature available in iOS 13 or later print("Available on iOS 13 or later") } else { // Fallback for earlier iOS versions print("Available on earlier versions") }

Swift @available availability checks iOS macOS version compatibility