我的应用程序需要与不同的操作系统版本兼容。
如何检测特定类是否可用于特定操作系统?
例如,NSPopover
只在狮子和更高版本中可用,那么如果用户使用雪豹,我如何检查操作系统是否支持NSPopover
?
发布于 2012-11-02 01:51:31
你可以这样做
if ([TheWantedClass class]) {
// The class exists so run code
} else {
// The class doesn't exist so use an alternate approach
}
或
if (NSClassFromString(@"TheWantedClass") != nil) {
// The class exists
} else {
// The class doesn't exist
}
https://developer.apple.com/documentation/foundation/1395135-nsclassfromstring
https://stackoverflow.com/questions/13182668
复制相似问题