How to detect iOS11 programmatically in Swift?

Viewed 15449

I saw in the WWDC video that there's some new swift function to detect iOS 11 availability.

How do I detect iOS11 with Swift?

2 Answers

Swift 3:

if #available(iOS 11.0, *) {
  // Running iOS 11 OR NEWER
} else {
  // Earlier version of iOS
}

More information is available in Declaration Attributes section of Apple's Swift Programming Guide.

Objective C:

if (@available(iOS 11, *)) {
  // Running iOS 11 OR NEWER
} else {
  // Earlier version of iOS
}
Related