测试目标中的程序中出现意外的“@" [英] unexpected '@' in program in test target

查看:61
本文介绍了测试目标中的程序中出现意外的“@"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下声明的字符串常量.此代码编译器在正常的应用程序调试和发布目标中.但是在应用程序的测试目标(Ctrl + U)中,我在测试目标的程序中遇到了意外的@"错误.使用 xcode 7.

模块已按照

在 .m 文件中用作,

NSURL * url = [NSURL URLWithString:URL_AC];

偶数声明

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

得到使用未声明的标识符 URL_AC"编译器错误.

解决方案

我发现了问题.'define' 有一些 #ifdef 宏.这是使用 build settings 中的 preprocessor declaration 控制的.在我的测试目标中它没有被定义.当我定义它时,编译器得到定义"并且所有错误都消失了.

#if 已定义(TEST0)#define URL0 "http://www.example.com"#elif 定义(TEST1)#define URL1 "http://www.example2.com"#万一

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.

解决方案

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

这篇关于测试目标中的程序中出现意外的“@"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆