Swift package breaks SwiftUI Xcode previews

I'm working on a new project supporting iOS 14 & 15 in Xcode 13. It's all swift and a combination of UIKit ad SwiftUI. Previews in the canvas were working great until a SwiftUI view was referenced from another view controller that imports our swift package. I'm using an intel Mac.

The diagnostic linker errors in the canvas range from things like:

HumanReadableSwiftError

ConfigurationError: noPreviewInfos(architecture: x86_64, sdkRoot: "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.0.sdk")

or

Could not find module 'MyModule' for target 'arm64-apple-ios-simulator'; found: x86_64-apple-ios-simulator, x86_64

 

I've searched around and tried things I've seen suggested elsewhere, like excluding the arm64 architecture, building active architecture only, etc... None of those seem to address the issue, and usually just produce slightly different error messages.

The swift packages I'm using are just plain swift packages that work fine otherwise. They don't have any dependencies of their own. Is this just an issue between SPM and SwiftUI? Is there something I need to adjust to make all of these things work together? I also tried reproducing the issue in a new project, and as soon as a file that imports my framework touches a SwiftUI file in any way, previews are broken for the whole app with linker errors.

Any help or just a sanity check are much appreciated. Most similar issues I find by searching around are using 3rd party dependency managers or have more complicated setups. This is a pretty easy/straightforward one and I can't seem to get past it.

Hi,

Sorry to hear you are having problems getting previews with swift packages working. We are currently tracking some related issues, but to be sure we have yours on the radar it'd be best to file a feedback with diagnostics and a sample project.

  1. When you get an error in Xcode Previews, an error banner appears in the canvas
  2. Click the "Diagnostics" button in that banner
  3. In the sheet that appears, click "Generate Report" in the bottom left of the sheet
  4. Attach (or make from the folder) the resulting zip file to the bug (will be named something like previews-diagnostics-0123456789.zip)
Swift package breaks SwiftUI Xcode previews
 
 
Q