英文:
Not able to use XCTUnwrap in Test Framework
问题
我正在尝试创建一个包括一些扩展的测试框架。我能够按照这里的建议在框架中导入 XCTest:https://stackoverflow.com/a/35102636/3475906
但是,每当我尝试使用 XCTUnwrap 时,我都会收到错误消息:“未解析的标识符 'XCTUnwrap'”
基本上,我想要类似于这样的东西:
import XCTest
extension Optional {
func unwrap() -> Wrapped {
do {
return try XCTUnwrap(self)
} catch {
print("处理错误")
}
}
}
有人有任何想法吗?
英文:
I am trying to create a test Framework that includes some extensions. I am able to import XCTest
in the framework by following the suggestions from here: https://stackoverflow.com/a/35102636/3475906
However, whenever I try to use XCTUnwrap I got error: Use of unresolved identifier 'XCTUnwrap'
Basically, I want something like this:
import XCTest
extension Optional {
func unwrap() -> Wrapped {
do {
return try XCTUnwrap(self)
} catch {
print("Handle error")
}
}
}
Does anybody have any idea?
答案1
得分: 5
XCTUnwrap
API 仅在主要测试捆绑目标中可用,而不在其他库或框架中可用。有两种方法可以解决此问题:
- 将您的
Optional
扩展移到主捆绑中,这显然不是您想要做的 - 修改您的测试框架目标中的以下构建设置:
SYSTEM_FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
);
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PLATFORM_DIR)/Developer/usr/lib",
);
SWIFT_INCLUDE_PATHS = "$(inherited) $(PLATFORM_DIR)/Developer/usr/lib"
英文:
The XCTUnwrap
API is only available in primary test bundle targets and not in other libraries or frameworks. There are two ways to fix this issue:
- Move your
Optional
extension to the main bundle which obviously not something you want to do - Modify the following build settings in your test framework target:
SYSTEM_FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
);
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PLATFORM_DIR)/Developer/usr/lib",
);
SWIFT_INCLUDE_PATHS = "$(inherited) $(PLATFORM_DIR)/Developer/usr/lib"
答案2
得分: 0
在至少 Xcode 11.4 版本中,您可以在项目或目标的“构建设置”中启用:
ENABLE_TESTING_SEARCH_PATHS = YES
英文:
At least since Xcode 11.4 you may just enable:
ENABLE_TESTING_SEARCH_PATHS = YES
in the "Build Settings" of your project or target.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论