" XXX-Swift.h"在测试项目中找不到文件 [英] "XXX-Swift.h" file not found in test project
问题描述
我正在尝试在 XCTestCase的方法中调用一个
测试项目中的子类。主项目的 NSObject
子类的方法。 NSObject
子类导入XXX-Swift.h头文件(我混合 Swift
和 Objective-C
代码)。当我运行主项目时,一切正常,但是当我运行调用该子类的对象的测试时,我得到一个错误,说导入中的 Swift
头文件是没找到。
I'm trying to call a method of a NSObject
subclass I have in the let's say "main" project within a method of a XCTestCase
subclass in the test project. The NSObject
subclass of the main project imports the "XXX-Swift.h" header file (I'm mixing Swift
and Objective-C
code). All works fine when I run the main project, but when I run the tests calling an object of that subclass, I get an error saying that the Swift
header file in the import is not found.
我想我错过了测试目标中的一些设置,但我找不到...我应该检查什么?或者我该怎么做才能解决这个问题?
I guess I'm missing some settings in the test target, but I don`t find which... what should I check? Or what should I do to solve this?
推荐答案
转到Xcode Project> Build Settings并输入header name,你会得到以下选项:
Go to Xcode Project > Build Settings and type "header name", you will get the below option:
确保必须存在一个名称为的文件: $(SWIFT_MODULE_NAME)-Swift.h
Make sure that there must exist a file with a name: $(SWIFT_MODULE_NAME)-Swift.h
然后在Build Settings下键入bridging header并确保bridging-header.h文件的路径正确存在。
Then type, "bridging header" under Build Settings and make sure that the path of "bridging-header.h" file exist correctly.
已编辑:
1)确保您的项目名称不包含空格
2)生成XXX-Swift.h文件在以下路径中,您需要将该路径添加到单元测试 - 转到构建设置,键入标题搜索路径并添加以下行
1) Make sure that your "Project Name" doesn't contains spaces 2) Well "XXX-Swift.h" file is generated at the following path, so you need to add that path to unit test - Go to build settings, type "Header Search Paths" and add the following line
"$(TARGET_TEMP_DIR)/../$(PROJECT_NAME).build/DerivedSources"
更多信息,请参考以下链接:iOS - 运行时找不到'MyProject-Swift.h'文件斯威夫特的单元测试
For more, you can refer this link : iOS - 'MyProject-Swift.h' file not found when running Unit Tests for Swift
这篇关于" XXX-Swift.h"在测试项目中找不到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!