问题
#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
回答1:
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.
来源:https://stackoverflow.com/questions/17481396/invalid-token-at-start-of-a-preprocessor-expression-xcode