选择watchOS目标时,我的Swift软件包无法编译。
错误消息为Failed to load module 'XCTest'
,构建错误详细信息为:
/Applications/Xcode-beta.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator6.0.sdk/usr/lib/swift/XCTest.swiftmodule/i386.swiftinterface:6:19: XCTest is not available when building for watchOS Simulator. Consider using
#if targetEnvironment(macCatalyst)to conditionally import this framework when building for Mac Catalyst.
watchOS中没有XCTest,所以我可以让我的Swift软件包为watchOS编译吗?
答案 0 :(得分:0)
#if !os(watchOS)
// XCTest code
#endif
答案 1 :(得分:0)
这是一个完全的骇客,但是我在开发过程中遇到的一种方法是暂时注释掉Package.swift文件中的.testTarget(name:dependencies:)
类型方法。之后,清理生成文件夹,然后为watchOS生成并运行。
我还为自己留下了#warning
,以确保在对Swift软件包进行任何提交之前都取消注释。
(值得补充的是,这是将所有测试代码包装在#if !os(watchOS)
条件中的补充。)