I am trying to see if this is possible. Looks like setting UICollectionViewFlowLayout's estimatedItemSize doesn't work very good in ios 9. It works perfectly fine ios 10. So i am thinking of implementing sizeForItemAt.. method only for ios 9. Is there anyway to do that using @available ?? Will be really helpful if someone can shed light.
let systemVersion = UIDevice.currentDevice().systemVersion
println("iOS\(systemVersion)")
if systemVersion == 9.0 {
//Do Something
}
You can use like below:
@available(iOS 10.0, *)
private func userNotificationCenter(center: UNUserNotificationCenter, willPresentNotification notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) {
logParklee.verbose("willPresentNotification")
}
Or
if #available(iOS 10, *) {
// use UIStackView
} else {
// show sad face emoji
}
Or
guard #available(iOS 9, *) else {
return
}
Or
@available(iOS 7, *)
func iOS7Work() {
// do stuff
if #available(iOS 8, *) {
iOS8Work()
}
}
@available(iOS 8, *)
func iOS8Work() {
// do stuff
if #available(iOS 9, *) {
iOS9Work()
}
}
@available(iOS 9, *)
func iOS9Work() {
// do stuff
}
I wanted to execute code when the version is lower iOS 11, here's how I did it:
if #available(iOS 11, *) {
// This is probably empty
} else {
// This code will only be executed if the version is < iOS 11
}
It's not the cleanest solution, but I couldn't find a better way and it does its job. 💡
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With