常用系統宏定義

#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 {
    // ...
}
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容