I am developing a Cocoa application and need to check whether the current OS X version is OS X 10.6 Snow Leopard
If the current version is Snow Leopard, I need to close the application with an error alert.
How can I find the current OS X version?
From the Apple menu in the corner of your screen, choose About This Mac. You should see the macOS name, such as macOS Monterey or macOS Big Sur, followed by its version number. If you need to know the build number as well, click the version number to see it.
The relevant Apple documentation can be found in Using SDK-Based Development: Determining the Version of a Framework.
They suggest either testing the existence of a specific class or method or to check the framework version number, e.g. NSAppKitVersionNumber
or NSFoundationVersionNumber
. The relevant frameworks also declare a number of constants for different os versions (NSApplication constants, Foundation Constants).
The relevant code can be as simple as:
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5) {
// Code for 10.6+ goes here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With