1

“<strong>使用基于 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.
4

1 回答 1

0

为了测试一个类,例如NSUserNotificationCenter,是否存在,做

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

为了测试一个常量,例如 NSWindowDidChangeBackingPropertiesNotification,是否存在,做

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

还请查看此答案:检查是否在运行时在 Obj-C 中定义了常量

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

BOOL NSRegularExpressionSearchIsAvailable = (&NSRegularExpressionSearch != NULL);
if (NSRegularExpressionSearchIsAvailable)
{
    //...
}
于 2012-11-03T01:13:08.830 回答