13

I'm building an application that needs to check what version of OS X is installed on a Mac. It is built against 10.9 Mavericks, but all of the Swift APIs are pretty much 10.10 only.

I'm trying to use the following, however it does not compile against the 10.9 SDK since it does not have these APIs, I know how to use if #available(OSX 10.10, *) to conditionally compile as per the different versions, however because NSProcessInfo is a 10.10+ API I can't use it to check to see if the Mac is running 10.9. This is the code I have so far (however it does not compile against the 10.9 SDK):

let osVersion = NSProcessInfo.processInfo().operatingSystemVersion
if osVersion.minorVersion == 9 {
    //  Do something for OS X 10.9 Mavericks
} else {
    // Do something for anything not Mavericks (10.10+)
}

Is there another way to check what OS the Mac is running in 10.9? Essentially I could wrap the above code with:

if #available(OSX 10.10, *) {
    let osVersion = NSProcessInfo.processInfo().operatingSystemVersion
    // Check OS version
} else {
    // Check OS version using a 10.9 API
}

I just don't know what to fill in for the // Check OS version using a 10.9 API section of that code block.

4
  • 1
    Possible duplicate of How do I determine the OS version at runtime in OS X or iOS (without using Gestalt)? Commented Apr 21, 2016 at 15:37
  • @jtbandes the answer in there uses an API that isn't in 10.9 it looks like Commented Apr 21, 2016 at 15:38
  • Check out the other answers. Commented Apr 21, 2016 at 15:38
  • Ah yes, found it very far down the page, sorry! Commented Apr 21, 2016 at 15:44

2 Answers 2

3

The same check will be used just put 10.9 code inside if for other version in else

if #available(OSX 10.9, *) {
 } else {
}
Sign up to request clarification or add additional context in comments.

1 Comment

This only checks the minimum version, so regardless of what system I am running, it will always be true.
1

2022, MacOS

let a = ProcessInfo.processInfo.operatingSystemVersion

let b = ProcessInfo.processInfo.operatingSystemVersionString

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.