如何在方法声明中使用预处理器宏?

时间:2015-07-20 03:48:09

标签: ios objective-c xcode

我经常在Xcode 6和7之间切换,并想要一种方法来避免像这样的构建警告。

  

执行中的冲突返回类型   ' supportedInterfaceOrientations':' UIInterfaceOrientationMask' (又名   ' enum UIInterfaceOrientationMask')vs' NSUInteger' (又名'未签名   长&#39)

我似乎无法使用同时满足两个版本Xcode的类型。所以我打算实现一个预处理器宏,它具有不同的值,具体取决于__IPHONE_9_0的值。

#ifdef __IPHONE_9_0
#define CompatibilityUserInterfaceMask  UIInterfaceOrientationMask
#else
#define CompatibilityUserInterfaceMask  NSUInteger
#endif

当我尝试实现这个时,虽然我遇到了构建错误。

- (CompatibilityUserInterfaceMask)supportedInterfaceOrientations { ... }

这是可能的,还是有人有其他想法可以达到同样的结果?

1 个答案:

答案 0 :(得分:2)

据我所知,你的宏应该可行,但如果你想要一个略微不同的方法(可以说是丑陋的):

#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000  
- (NSUInteger)supportedInterfaceOrientations  
#else  
- (UIInterfaceOrientationMask)supportedInterfaceOrientations  
#endif  
相关问题