系统宏

常用系统宏定义

2016-10-09  本文已影响17人  sunflower1518
#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 {
    // ...
}
上一篇下一篇

猜你喜欢

热点阅读