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?
Git clone TestPackage1 & TestPackage2 at the same level in a directory
Open TestPackage2 and go to Sources/TestPackage2/SwiftUIView2.swift and try to start an Xcode preview
You get the error I mentioned above
Remove the TestPackage1 dependency in TestPackage2/Package.swift
Code Block swift dependencies: ["TestPackage1"]
to: Code Block swift dependencies: []
Code Block swift products: [ .library( name: "UIComponents", type: .dynamic, /* added parameter */ targets: ["UIComponents"]) ],
Code Block swift products: [ .library( name: "AppPackage", type: .dynamic, /* added parameter */ targets: ["AppPackage"]) ], dependencies: [ .package(path: "../UIComponents") ],
This needs an updated answer. The last official answer was almost a year ago saying there is no work-around and is being "actively investigated". What is the timeline for this to be solved? Utterly ridiculous.
My package's min iOS Version was iOS 12. All my SwiftUI views are obviously only available in iOS 13+. When developing I set the min iOS Version to iOS 13 and it works. Not very pleasant but at least I can use previews while developing now.
I continue to see issues with this. We need this fixed ASAP
In my case, swift package generate-xcodeproj
and opening the .xcodeproj file instead of Package.swift
made it possible to access the Xcode preview.
Just ran across this on a project that is being refactored to have "better" code structure. This inability to preview views within a package that depend upon another package is pretty surprising, given the push toward Packages, the age of this post, and the number of upvotes here.
In my experience, it's not that it couldn't find the package—adding the full path to the package ("/my/specific/dir/PackageName" instead of "../PackageName") did not work.
The project builds and runs fine for simulators and the automated tests run and pass, but it does not build for previews.
I sometimes see crashes, and sometimes the inline xcode source code error "could not find module '' for target 'x86_64-apple-ios-simulator'; found: arm64, arm64-apple-ios-simulator".
Those details seem interesting (not available for x86 when running simulator)—is this what others are seeing? I've tried setting various architectures—my Mac, my Mac (catalyst), iOS simulator running iOS15, etc.
For now, my workaround may be to not have packages that depend upon each other, which partly defeats the purpose. And I may file a bug report, but I may find existing and upvote.