我正在制作一个 iPhone 应用程序,我想做宽屏检测,所以我做了一堆#define
's,我想用它做一个 if 语句。
// Device and Widescreen Detection
#define IS_WIDESCREEN ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
// iPhone
#define IS_IPHONE ( [ [ [ UIDevice currentDevice ] model ] isEqualToString: @"iPhone" ] ) || ( [ [ [ UIDevice currentDevice ] model ] isEqualToString: @"iPhone Simulator" ] ) )
#define IS_IPHONE_5 ( IS_IPHONE && IS_WIDESCREEN )
// iPod Touch
#define IS_IPOD ( [ [ [ UIDevice currentDevice ] model ] isEqualToString: @"iPod touch" ] )
#define IS_IPOD_5 ( IS_IPOD && IS_WIDESCREEN )
// iPad
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
我想做一个 if 语句说
if (IS_IPHONE_5) {
...
} else {
...
}
问题是 if 语句返回一个错误,XCode 一直告诉我这样做
if (IS_IPHONE_5 {
...
} else {
...
}
或这个
if IS_IPHONE_5 {
...
} else {
...
}
否则会出错。写这个的正确方法是什么?