'unexpected '@'in program' 构建测试时出错

'unexpected '@' in program' error while building tests

在我的项目中,我使用了来自 ReactiveCocoa 的名为 keypath 的宏:

NSString *lowercaseStringPath = @keypath(NSString.new, lowercaseString);
// => @"lowercaseString"

 * @endcode
 *
 * ... the macro returns an \c NSString containing all but the first path
 * component or argument (e.g., @"lowercaseString.UTF8String", @"version").
 *
 * In addition to simply creating a key path, this macro ensures that the key
 * path is valid at compile-time (causing a syntax error if not), and supports
 * refactoring, such that changing the name of the property will also update any
 * uses of \@keypath.
 */
#define keypath(...) \
    metamacro_if_eq(1, metamacro_argcount(__VA_ARGS__))(keypath1(__VA_ARGS__))(keypath2(__VA_ARGS__))

#define keypath1(PATH) \
    (((void)(NO && ((void)PATH, NO)), strchr(# PATH, '.') + 1))

#define keypath2(OBJ, PATH) \
    (((void)(NO && ((void)OBJ.PATH, NO)), # PATH))

它在主要目标上运行良好。但是当我尝试 运行 测试时,它显示了这个错误:

我看到了this post

这与我项目中的问题非常相似。但仍然不同,没有有用的答案。 有谁知道如何解决它?因为我真的被困在这里,不知道该去哪里。

TokenModel 不应编译到您的测试目标中。测试目标应仅包含测试代码(以及任何需要的库)。

转到您的测试目标设置。在测试部分的常规下,确保您已指定 "Host Application"。您可能还需要启用 "Allow testing Host Application APIs" 复选框。

然后从您的测试目标中删除生产代码。