【问题标题】:How can I use a preprocessor macro in a method declaration?如何在方法声明中使用预处理器宏?
【发布时间】:2015-10-09 02:35:25
【问题描述】:

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

实现中的返回类型冲突 'supportedInterfaceOrientations':'UIInterfaceOrientationMask'(又名 “枚举 UIInterfaceOrientationMask”)与“NSUInteger”(又名“无符号” 长')

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

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

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

- (CompatibilityUserInterfaceMask)supportedInterfaceOrientations { ... }

这可能吗,或者有人有其他想法来达到相同的结果吗?

【问题讨论】:

    标签: ios objective-c xcode


    【解决方案1】:

    据我所知,您的宏应该可以正常工作,但如果您想要稍微不同的方法(可以说更丑):

    #if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000  
    - (NSUInteger)supportedInterfaceOrientations  
    #else  
    - (UIInterfaceOrientationMask)supportedInterfaceOrientations  
    #endif  
    

    【讨论】:

      猜你喜欢
      • 2019-03-07
      • 1970-01-01
      • 2011-05-04
      • 1970-01-01
      • 2017-08-09
      • 2011-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多