“XXX-Swift.h"在测试项目中找不到文件 [英] "XXX-Swift.h" file not found in test project
问题描述
我正在尝试调用我在测试项目中的 XCTestCase
子类的方法中的main"项目中的 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"文件是在以下路径生成的,因此您需要将该路径添加到单元测试 - 转到构建设置,键入Header Search Paths"并添加以下行
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 - 运行 Swift 单元测试时找不到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屋!