1

It has been common advice to use the NSAppKitVersionNumber to check for new features provided by Cocoa frameworks at runtime:

https://developer.apple.com/library/mac/releasenotes/AppKit/RN-AppKit/

One typical use of this is to floor() the value, and check against the values provided in NSApplication.h. For instance:

if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_8) {
  /* On a 10.8.x or earlier system */
} else if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_9) {
  /* On a 10.9 - 10.9.x system */
} else {
  /* 10.10 or later system */
}

In OS X 10.10 and Xcode 6.2, NSApplication.h includes:

/* The version of the AppKit framework */
APPKIT_EXTERN const double NSAppKitVersionNumber;

#define NSAppKitVersionNumber10_0 577
#define NSAppKitVersionNumber10_1 620
#define NSAppKitVersionNumber10_2 663
#define NSAppKitVersionNumber10_2_3 663.6
#define NSAppKitVersionNumber10_3 743
#define NSAppKitVersionNumber10_3_2 743.14
#define NSAppKitVersionNumber10_3_3 743.2
#define NSAppKitVersionNumber10_3_5 743.24
#define NSAppKitVersionNumber10_3_7 743.33
#define NSAppKitVersionNumber10_3_9 743.36
#define NSAppKitVersionNumber10_4 824
#define NSAppKitVersionNumber10_4_1 824.1
#define NSAppKitVersionNumber10_4_3 824.23
#define NSAppKitVersionNumber10_4_4 824.33
#define NSAppKitVersionNumber10_4_7 824.41
#define NSAppKitVersionNumber10_5 949
#define NSAppKitVersionNumber10_5_2 949.27
#define NSAppKitVersionNumber10_5_3 949.33
#define NSAppKitVersionNumber10_6 1038
#define NSAppKitVersionNumber10_7 1138
#define NSAppKitVersionNumber10_7_2 1138.23
#define NSAppKitVersionNumber10_7_3 1138.32
#define NSAppKitVersionNumber10_7_4 1138.47
#define NSAppKitVersionNumber10_8 1187
#define NSAppKitVersionNumber10_9 1265

Notably missing is NSAppKitVersionNumber10_10 for OS X 10.10 Yosemite.

Has the 10_10 version been specifically excluded, and for what reason?

Do these constants typically only show up in the version after they are current?

Or is this method of checking version numbers now outdated? If so, what is the replacement?

pkamb
  • 33,281
  • 23
  • 160
  • 191

2 Answers2

2

Do these constants typically only show up in the version after they are current?

Yes. Similarly, the 10.9 SDK only defines up through NSAppKitVersionNumber10_8.

You'll notice the code snippet you quoted doesn't include an explicit check for 10.10. It's just the implicit fallback after all of the other checks.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • Good to know, although I still don't understand the *reason* for not including `10_10` in OS X 10.10. – pkamb Apr 14 '15 at 17:58
  • 1
    I'm guessing because the actual version number of the shipping AppKit of 10.10 was not finalized when the 10.10 SDK was in beta. That is, the SDK has to be finalized before the framework is. – Ken Thomases Apr 15 '15 at 01:10
2

As Ken pointed out, the NSAppKitVersionNumber isn't explicit. One other aspect to be aware of is the availability, notice for example:

NSAppKitVersionNumber10_8

The AppKit framework included in OS X v10.8.
Available in OS X v10.9 and later.

A hypothetical example in a future version of NSApplication.h:

#define NSAppKitVersionNumber10_10 1343.14

Which might equate to:

NSAppKitVersionNumber10_10

The AppKit framework included in OS X v10.10.
Available in OS X v11.0 and later.

There are some other useful constants that might prove useful for version checks:

Marking updated APIs in headers:

New APIs in headers are marked with decorations that include references to "10_10”:

NS_AVAILABLE_MAC(10_10)
NS_AVAILABLE(10_10, <iOS Release>)
NS_CLASS_AVAILABLE(10_10, <iOS Release>)
NS_ENUM_AVAILABLE(10_10)

Constructs:

#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10
 ...
#endif

Deprecated APIs are marked with:

NS_DEPRECATED_MAC(<Release when introduced>, 10_10)
NS_DEPRECATED_MAC(<Release when introduced>, 10_10, "Suggested alternative”)

In 10.10, the deprecated attribute has been added to many previously soft-deprecated methods. Please be aware of deprecation warnings and modify your code to use supported alternatives. Searching AppKit headers for NS_DEPRECATED_MAC and filtering for 10_10 will yield a list of affected symbols.

AppKit Framework Reference

l'L'l
  • 44,951
  • 10
  • 95
  • 146