3
#define A7VERSION() ({[[[[[UIDevice currentDevice] systemVersion] componentsSeparatedByString:@"."] objectAtIndex:0] intValue];})

#define IS_OS_7 A7VERSION()>=7

The above declaration seems to compile well.

But as soon as I add it a .m file I get the following exception "invalid token at start of a preprocessor expression". I am not able to understand where I could be wrong

@implementation AppViewController
#if IS_OS_7
….
#else
….  
#endif
@end
weber67
  • 525
  • 1
  • 9
  • 18
  • Due to the dynamic nature of Objective-C, the value of method calls cannot be determined at compile time, meaning that a runtime check is all that you can do. A good list of runtime checks is here: http://stackoverflow.com/questions/3339722/check-iphone-ios-version – CodaFi Jul 05 '13 at 05:05
  • 2
    THIS IS NOT A DUPLICATE QUESTION. Its related to preprocessor . Nor does my question title specify its a version check code.I was expecting it to work at runtime which was wrong and corrected by @bbum – weber67 Jul 06 '13 at 06:21

1 Answers1

10

The problem has nothing to do with iOS 7.

Your #define does not lead to something that can be resolved at compile time. An #ifdef only works if the conditional is something that can be determined at compile time. It cannot be used to change behavior at runtime based on the environment an app is running on.

jscs
  • 63,694
  • 13
  • 151
  • 195
bbum
  • 162,346
  • 23
  • 271
  • 359