Invalid token at start of a preprocessor expression Xcode [duplicate]

匆匆过客 提交于 2019-12-21 20:36:16

问题


#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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!