@available, #available
#available - ็จๆผ code block
@available - ็จๆผ method ๆ class ๅ้ข
// โญ๏ธ 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 case
extension Bool {
/// โญ๏ธ Bool.iOS14
static var iOS14: Bool {
guard #available(iOS 14, *) else { return false }
return true
}
}
SwiftLee โฉ How to create a Conditional View Modifier in SwiftUI
Last updated