How to use a preprocessor macro in a method declaration?

I often go between Xcode 6 and 7 and want to avoid build warnings like this.

Conflicting return type when implementing 'supportedInterfaceOrientations': 'UIInterfaceOrientationMask' (aka 'enum UIInterfaceOrientationMask') vs 'NSUInteger' (aka 'unsigned long')

I cannot use a type that will satisfy both versions of Xcode at the same time. Therefore, I was going to implement a preprocessor macro that had different values ​​depending on the value of __IPHONE_9_0.

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

When I try to implement this, although I get a build error.

- (CompatibilityUserInterfaceMask)supportedInterfaceOrientations { ... }

Is this possible, or does anyone have other ideas to achieve the same result?

+4
source share
1

, , (, ):

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

Source: https://habr.com/ru/post/1598640/


All Articles