How to detect iOS11 programmatically in Swift?

Alex Stone picture Alex Stone · Sep 22, 2017 · Viewed 14.1k times · Source

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?

Answer

Alex Stone picture Alex Stone · Sep 22, 2017

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.