我经常在 Xcode 6 和 7 之间切换,并且想要一种方法来避免像这样的构建警告。
Conflicting return type in implementation of 'supportedInterfaceOrientations': 'UIInterfaceOrientationMask' (aka 'enum UIInterfaceOrientationMask') vs 'NSUInteger' (aka 'unsigned long')
我似乎无法使用同时满足两个版本的 Xcode 的类型。所以我打算实现一个预处理器宏,它根据 __IPHONE_9_0 的值具有不同的值。
#ifdef __IPHONE_9_0
#define CompatibilityUserInterfaceMask UIInterfaceOrientationMask
#else
#define CompatibilityUserInterfaceMask NSUInteger
#endif
尽管我遇到构建错误,但尝试实现它时。
- (CompatibilityUserInterfaceMask)supportedInterfaceOrientations { ... }
这可能吗,或者有人有其他想法来实现相同的结果吗?
最佳答案
据我所知,您的宏应该可以正常工作,但如果您想要一种稍微不同的方法(可以说更丑陋):
#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
- (NSUInteger)supportedInterfaceOrientations
#else
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
#endif
关于ios - 如何在方法声明中使用预处理器宏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31508572/