Swift 3 - @ is only available for ios 9, not ios 10

I'm trying to figure out if this is possible. It looks like the UICollectionViewFlowLayout setting is appreciated. ItemSize does not work very well in ios 9. It works fine with ios 10. So I’m thinking about implementing the sizeForItemAt method .. only for ios 9. Is there any way to do this with @available ?? It will be really helpful if someone can shed light.

+8
source share
4 answers

I wanted to execute the code when iOS version 11 is lower, here is 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
}

This is not the cleanest solution, but I could not find a better way, and it does its job. 💡

+11
source

? docs , :

@available(iOS, obsoleted: 10.0)

@available(iOS, introduced: 9.0, obsoleted: 10.0)
+6
let systemVersion = UIDevice.currentDevice().systemVersion
println("iOS\(systemVersion)")

if systemVersion == 9.0 {
  //Do Something
}

, :

@available(iOS 10.0, *)
private func userNotificationCenter(center: UNUserNotificationCenter, willPresentNotification notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) {
    logParklee.verbose("willPresentNotification")
}

if #available(iOS 10, *) {
    // use UIStackView
} else {
    // show sad face emoji
}

guard #available(iOS 9, *) else {
    return
}

@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
}
+1

, iOS 10, :

if #available(*, iOS 9) {
    // Code here will only run on iOS 9 and below.
}
0
source

Source: https://habr.com/ru/post/1661568/


All Articles