unexpected '@' in program in test target

独自空忆成欢 提交于 2019-12-23 04:29:31

问题


I have string constant declared as below. This code compilers in normal app debug and release target. But in app's test target (Ctrl + U), I got error that unexpected '@' in program in test target. Using xcode 7.

Modules are enabled as answered in this question.

HeaderA.h

#define URL_A   "http://www.example.com/service"

HeaderB.h

#define URL_AC          @URL_A

Got error here, unexpected '@' in program. Expanded from macro @URL_AC

Modules are enabled as answered in this question.

Used in an .m file as,

NSURL * url = [NSURL URLWithString:URL_AC];

Even declaration of

#define URL_AC      @"https://www.example.com/service?format=json"

got 'Use of undeclared identifier URL_AC' compiler error.


回答1:


I found the problem. The 'define' have some #ifdef macros. And this is controlled using preprocessor declaration in the build settings. In my test target it was not defined. When I defined it, compiler gets the 'define' and all errors gone.

#if defined(TEST0)
#define URL0    "http://www.example.com"

#elif defined(TEST1)
#define URL1    "http://www.example2.com"

#endif


来源:https://stackoverflow.com/questions/33256221/unexpected-in-program-in-test-target

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