Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Package fails to compile for watchOS

My Swift Package fails to compile when selecting the watchOS target.

enter image description here

The error message is Failed to load module 'XCTest' and build error details is:

/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.

There is no XCTest in watchOS so do I get my Swift Package to compile for watchOS?

like image 888
TruMan1 Avatar asked Aug 22 '19 04:08

TruMan1


1 Answers

It's a total hack but one way I've been getting round this during development is to temporarily comment out the .testTarget(name:dependencies:) type method in the Package.swift file. After that, clean the build folder, then build and run for watchOS.

I also leave a #warning for myself to make sure I uncomment before making any commits to my Swift Package.

(It's worth adding that this is in addition to wrapping all test code in #if !os(watchOS) conditionals.)

like image 58
Neil Smith Avatar answered Jan 14 '23 13:01

Neil Smith