@available, #available
// ⭐️ if #available
// iOS 13 or later    any other unknown platforms announced in the future
//         ↳  ╭────╮  ↑
if #available(iOS 13, *) {
    // use UICollectionViewCompositionalLayout
} else {
    // show sad face emoji
}
// ⭐️ guard #available
guard #available(iOS 13, *) else { return }
// ⭐️ @available
@available(iOS 11, macOS 10.13, *)
func newMethod() {
    // Use iOS 11 APIs.
}
#if os(iOS)
var body: some View {
    NavigationView{ ... }
    .navigationViewStyle(StackNavigationViewStyle())
}
#else
var body: some View {
    NavigationView{ ... }
    .navigationViewStyle(DoubleColumnNavigationViewStyle())
}
#endif- Swift Language Reference ⟩ Attributes 
check iOS version
// use case
Text("Hello, world!")
   .padding()
   .if(.iOS14) { $0.background(Color.red) }    // ⭐️ use caseextension Bool {
     /// ⭐️ Bool.iOS14
     static var iOS14: Bool {
         guard #available(iOS 14, *) else { return false }
         return true
     }
 }Last updated
Was this helpful?