常用系统宏定义

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0
// iOS SDK 7.0 以后版本的处理
#else
// iOS SDK 7.0 之前版本的处理
#endif

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_7_0
// 如果选择(iOS Deployment Target)的最低支持版本在iOS7.0及以上才可以使用
#endif

#if TARGET_OS_IPHONE
//iphone 程序
#endif

#if DEBUG
//debug 模式
#endif

#if TARGET_IPHONE_SIMULATOR
//模拟器运行
//@"iRate could not open the ratings page because the App Store is not available on the iOS simulator";
#endif

#if !__has_feature(objc_arc)
//非arc环境
#error This class requires automatic reference counting
#endif

判断该ios系统 是否有某个类/方法

//判断该ios系统 是否有某个类
#if __IPHONE_OS_VERSION_MAX_ALLOWED > 80000
// Weakly Linked判断
if ([UIAlertController class]) {
    // 使用UIAlertController...
} else {
    // 使用旧的方案...
}
#endif

//也可以如下判断:
Class class = NSClassFromString (@"UIAlertController");
if (class) {
    // 使用UIAlertController...
} else {
    // 使用旧的方案...
}

//判断是否相应某方法方法
if ([UITableViewCell instancesRespondToSelector:@selector (setSeparatorInset:)]) {
    // ...
} else {
    // ...
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容