1

Using SDK-Based Development” explains how to use weakly linked classes, methods, and functions ...

I have used this e.g.

if ([NSByteCountFormatter class]) {
    ...
}

Is there any way to detect supported options e.g.

NSRegularExpressionSearch
The search string is treated as an ICU-compatible regular expression.
If set, no other options can apply except NSCaseInsensitiveSearch and NSAnchoredSearch.
You can use this option only with the rangeOfString:... methods and stringByReplacingOccurrencesOfString:withString:options:range:.

Available in OS X v10.7 and later.
Milliways
  • 1,265
  • 1
  • 12
  • 26

1 Answers1

0

For testing whether a class, e.g. NSUserNotificationCenter, exists, do

if(NSClassFromString(@"NSUserNotificationCenter"))
{
    //...
}

For testing whether a constant, e.g. NSWindowDidChangeBackingPropertiesNotification, exists, do

BOOL NSWindowDidChangeBackingPropertiesNotificationIsAvailable = (&NSWindowDidChangeBackingPropertiesNotification != NULL);
if (NSWindowDidChangeBackingPropertiesNotificationIsAvailable) 
{
    //...
}

Check out this answer also: Check if constant is defined at runtime in Obj-C

In your case, this looks like

BOOL NSRegularExpressionSearchIsAvailable = (&NSRegularExpressionSearch != NULL);
if (NSRegularExpressionSearchIsAvailable)
{
    //...
}
Community
  • 1
  • 1
Nate Chandler
  • 4,533
  • 1
  • 23
  • 32
  • 1
    This may work with NSWindowDidChangeBackingPropertiesNotification which is defined as APPKIT_EXTERN NSString * const NSWindowDidExitVersionBrowserNotification, so you can take its address. NSRegularExpressionSearch is defined in NSString.h as NSRegularExpressionSearch NS_ENUM_AVAILABLE(10_7, 3_2) = 1024 So you can't take its address, and would be converted at compile time. – Milliways Nov 03 '12 at 02:32