Cocoa 有没有办法检测SDK中支持的选项
“使用基于SDK的开发”“说明如何使用弱链接的类、方法和函数 我用过这个Cocoa 有没有办法检测SDK中支持的选项,cocoa,osx-mountain-lion,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 NSCaseIn
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.
要测试类(例如
NSUserNotificationCenter
)是否存在,请执行以下操作
if(NSClassFromString(@"NSUserNotificationCenter"))
{
//...
}
BOOL NSWindowDidChangeBackingPropertiesNotificationIsAvailable = (&NSWindowDidChangeBackingPropertiesNotification != NULL);
if (NSWindowDidChangeBackingPropertiesNotificationIsAvailable)
{
//...
}
要测试常量(例如NSWindowDidChangeBackingPropertiesNotification)是否存在,请执行以下操作
if(NSClassFromString(@"NSUserNotificationCenter"))
{
//...
}
BOOL NSWindowDidChangeBackingPropertiesNotificationIsAvailable = (&NSWindowDidChangeBackingPropertiesNotification != NULL);
if (NSWindowDidChangeBackingPropertiesNotificationIsAvailable)
{
//...
}
也请查看此答案:
在你的情况下,这看起来像
BOOL NSRegularExpressionSearchIsAvailable = (&NSRegularExpressionSearch != NULL);
if (NSRegularExpressionSearchIsAvailable)
{
//...
}
这可能适用于定义为APPKIT_EXTERN NSString*常量NSWindowDidExitVersionBrowserNotification的NSWindowDidChangebackingProperties通知,因此您可以获取其地址。NSRegularExpressionSearch在NSString.h中定义为NSRegularExpressionSearch NS_ENUM_AVAILABLE(10_7,3_2)=1024,因此您无法获取其地址,并将在编译时转换。