预处理器表达式 Xcode 开始时的令牌无效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17481396/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Invalid token at start of a preprocessor expression Xcode
提问by weber67
#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
但是,一旦我将它添加到 .m 文件,我就会收到以下异常“预处理器表达式开始时的令牌无效”。我不明白我哪里错了
@implementation AppViewController
#if IS_OS_7
….
#else
….
#endif
@end
回答by bbum
The problem has nothing to do with iOS 7.
该问题与 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.
您#define
不会导致可以在编译时解决的问题。An#ifdef
仅在条件是可以在编译时确定的情况下才有效。它不能用于根据应用程序运行的环境在运行时更改行为。