I think in case of Swift
the best way for checking the API
availability is Automatic operating system API availability checking
that's new feature released with iOS9
and Swift2
if #available(iOS 9, *) {
// use UIApplicationLaunchOptionsShortcutItemKey
} else {
// no available
}
#available
is going to check whether are we using iOS 9 or later, or any other unknown platforms like watchOS
so the *
is also here.
If your code is inside a function then you can use #available
with guard
like this.
guard #available(iOS 9, *) else {
return
}
Mark your methods and class as well like
@available(iOS 9, *)
func useMyStackView() {
// use UIStackView
}
@available
works similarly to #available
so If your deployment target is iOS7
or less than 9, you can't call that useMyStackView()