Available
Code
guard #available(iOS 14, *) else {
print("Returning if iOS 13 or lower")
return
}
print("This code only runs on iOS 14 and up")
if #available(iOS 15, *) { }
avanderlee | @available / available
@available(iOS 13.0, macOS 10.15, *)
public class AsyncNetwork { }
sarunw | how-to-handle-api-changes-with-@available
@available
vs #available
#available
is a tool for API consumer.
checking for the availability
@available
is a tool for API creator.
specify availability
Conditional directive
hasAttribute(AttributeName)
#if hasAttribute(preconcurrency)
@preconcurrency
#endif
protocol P: Sendable { func f() func g() }
canImport(OSLibrary)
further explained in check Library
#if canImport(UIKit)
import UIKit
#endif
sarunw | conditional compilation