Xcode Previews doesn't work when used in a package that imports other packages.

I keep getting a Xcode Previews error in Xcode 12 from a package that imports other packages. As soon as I remove the dependency I'm able to see the SwiftUI preview. I'm only able to use previews in packages that have no dependencies

The error I get is: "LoadingError: failed to load library at path...Library not loaded " then it point to the dependency that it could not load in the current package.

How can I access Xcode Previews from a package that depends on other packages?
Answered by Developer Tools Engineer in 622246022
Hi,

Sorry to hear you are having problems. We have a received a feedback tracking this same issue, and we are actively investigating it. So far no known workaround.

Does anyone know if this is still an issue with Xcode 14? It is on 13.3.1.

Still having this problem in Xcode 13.4.1. What the heck

Any estimation on when this bug can be fixed?

I'm encountering the same error.

Hi, is there any update regarding this? I'm running into the same issue on Xcode 14.1, and I'm wondering if there's something I can do on my end to get around it.

Currently, the only way around this is to create a dummy project that integrates the package. Instantiate the views in the dummy project and Xcode Previews will work.

How is it now 2023, XCode 14, and this is still a problem? This issue exists even on the beta (Which I kind of expect), but the fact that it's nearly 2 years later and we're still battling this issue? Also, for more context, you don't even need to be working on a package that has another dependency. I'm currently working on a package that has NO dependencies, and I still can't get previews to work without first building, then reloading the preview manually. Apple, how do you expect us to adopt SwiftUI if you can't even get the minimum working properly?

same problem here

Still seeing this in XCode 14.2. Very disappointing

The issue still manifests in Xcode 15 beta 2. It's now June of 2023.

You guys must be new here. Apple Engineering never fixes ANYTHING in fewer than seven years and they maintain absolute radio silence the entire time. There are no updates. There will never BE any updates. The issue will continue until someone high enough in the organization is affected by it. See you in 2031.

Issue still present on Xcode15 beta 7, and honestly this prevents the creations of connected chains of swiftui packages, to modularize your UI code...

Bump because sadly this is still an issue

Xcode 15.0.1, issue still persists, Completely beating the purpose of breaking your code into modules. @Developer Tools Engineer Please, do something!

I too am facing this issue, interestingly it's happening on my AnnouncementModule package, not necessarily on a preview of a package, of a package. I've been doing some serious DEEP diving into this issue, and if I manage to find a solution, I'll share back here. My gut says this isn't an "Apple" issue, but more of a "Dev" issue and not understanding some really obscure technical thing.

The image here shows how my dependency tree looks in a reproducible example. I am able to get previews working just fine for Design which is incredibly odd, given it's a dependency for AnnouncementModule.

I think the issue isn't that all package imports break Xcode Previews. I am currently building a Swift Package where I use SwiftUI previews. I am integrating 2 packages simultaneously into this target and integrating the first one was a breeze. As soon as I introduced the second one, my preview crashes and I am getting an error:

I think the issue here is that some trait of that second Package causes Previews to break. For this second package, there are some setup steps that I cannot take in a Swift Package like Info.plist entries. It would be great if Xcode or the Xcode preview failure error would give an exact reason why this second package was unable to be loaded.

Xcode Previews doesn't work when used in a package that imports other packages.
 
 
Q