有没有办法检测SDK中支持的选项

时间:2012-11-03 00:44:20

标签: cocoa osx-mountain-lion

使用基于SDK的开发”解释了如何使用弱链接的类,方法和函数......

我用过这个。

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

有没有办法检测支持的选项,例如

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.

1 个答案:

答案 0 :(得分:0)

用于测试是否有课程,例如NSUserNotificationCenter,存在,执行

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

用于测试是否为常数,例如NSWindowDidChangeBackingPropertiesNotification,exists,do

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

同时查看此答案:Check if constant is defined at runtime in Obj-C

在您的情况下,这看起来像

BOOL NSRegularExpressionSearchIsAvailable = (&NSRegularExpressionSearch != NULL);
if (NSRegularExpressionSearchIsAvailable)
{
    //...
}