How to detect iOS11 programmatically in Swift?

15,311

Solution 1

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.

Solution 2

Objective C:

if (@available(iOS 11, *)) {
  // Running iOS 11 OR NEWER
} else {
  // Earlier version of iOS
}
Share:
15,311

Related videos on Youtube

Alex Stone
Author by

Alex Stone

When people asked me what I wanted to do for work 10 years ago, I did not know too well, so I just said "Something to do with computers". As I look at the last 10 years, I see that I did quite a lot of work all kinds of computers. From fiddling with microcontrollers and assembler code to writing data processing scripts to physically assembling computer consoles. The big step forward came when I learned to think about software in a structured, object-oriented way, as this allowed me to make software do things that I want it to do. Right now I'm proficient in two high level programming languages - Objective-C and Java and have touched just about every framework available for iOS. I've also became a hacker/maker and have completed a number of projects involving software and hardware. Right now I'm in my early 30s and when I ask myself "What would I like to do in the next 10 years?", my answer is "something with the human brain". The seeds are already there - I've picked up an interest in biology, cognitive science and neuroscience, enough to converse with real people. I've done first-hand research into sleep and made discoveries. I've taken classes in synthetic biology, performing manipulations on the bacteria genome. I've learned a lot about the neurotransmitter systems of the human brain, as well as how a biological organism develops. It seems like there are a lot of similarities between the object-oriented concepts I use in the daily programming tasks and how biological organisms operate. This makes me hopeful that by the time I'm in my late 30s, I would be able to work and program some form of biological computer or just plain hack the human brain.

Updated on August 29, 2020

Comments

  • Alex Stone
    Alex Stone almost 4 years

    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?

  • Nicolas Miari
    Nicolas Miari almost 7 years
    This isn't "some new swift function"; it has been around for a while.