问题
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