SwiftUI Preview don't work in Package with dependencies

Hi, I using packages to modularize my app's features, so my package contains Views. I'm unable to get the preview working in from any of my packages.

SwiftUI preview is complaining that it couldn't find the dependency module.

MessageSendFailure: Message send failure for send previewInstances message to agent

==================================

|  RemoteHumanReadableError
|  
|  LoadingError: failed to load library at path "/Users/karthik/Library/Developer/Xcode/DerivedData/WWoC-eovhbulekrmpsfbtdmwyilxornun/Build/Intermediates.noindex/Previews/WWoC/Products/Debug-iphonesimulator/PackageFrameworks/Groups.framework/Groups": Optional(dlopen(/Users/karthik/Library/Developer/Xcode/DerivedData/WWoC-eovhbulekrmpsfbtdmwyilxornun/Build/Intermediates.noindex/Previews/WWoC/Products/Debug-iphonesimulator/PackageFrameworks/Groups.framework/Groups, 0x0000): Library not loaded: @rpath/UIConvenience.framework/UIConvenience
|    Referenced from: /Users/karthik/Library/Developer/Xcode/DerivedData/WWoC-eovhbulekrmpsfbtdmwyilxornun/Build/Intermediates.noindex/Previews/WWoC/Products/Debug-iphonesimulator/PackageFrameworks/Groups.framework/Groups
|    Reason: tried: '/Users/karthik/Library/Developer/Xcode/DerivedData/WWoC-eovhbulekrmpsfbtdmwyilxornun/Build/Intermediates.noindex/Previews/WWoC/Products/Debug-iphonesimulator/UIConvenience.framework/UIConvenience' (no such file), '/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/UIConvenience.framework/UIConvenience' (no such file))

I noticed that that the preview starts to work as soon as I remove all the dependencies on a package. It looks like SwiftUI preview is not working for the packages with dependencies.

I'm seeing this bug in Xcode 12.5 and in Xcode 13.0 beta 2 ss well.

Can some please help me with this bug. At least please confirm if, at all, this feature is implemented in Xcode.

Post not yet marked as solved Up vote post of karthikkeyan Down vote post of karthikkeyan
3.6k views

Replies

I have the same problem, and it's quite annoying 😕 As a workaround, I use the package as a local dependency in a full app project.

Here is the tip:

I created a PreviewTester PreviewProvider, in which I reference a preview I want to see (requires to make it public, which I don't like at all, but I just don't commit it).

struct PreviewTester: PreviewProvider {
	static var previews: some View {
		YourView_Previews.previews
	}
}

Then I start the preview, pin it, and edit the view in the package source file.

I have the same error. I have the following structure (simplified a little), where the packages are local swift packages.

  • iOS Target
  • watchOS Target
  • watchOS Extension Target
  • Package A
  • Package B
  • Package C

The dependencies look something like this for the iOS Target:

iOS Target -> Package A -> Package C

When a scheme for the iOS Target is active, all previews work fine, but when I activate a "Package A" scheme to reduce the build time, then the Xcode Preview Agent crashes because Package A depends on Package C.

Add a Comment