Swift Package Manager + Dependency: How to View Previews?

  1. Assume you have a working swift package that previews a view see the following question on how to achieve that (https://developer.apple.com/forums/thread/651547?login=true&page=1#617372022). Note make sure your view is in the root folder of the package or live previews will not work.

  2. Add a dependency to the package. Example shown below


The Problem

Currently when you add a swift package manager dependency to a swift package in which you want to view a live preview you receive the following error:

The Question

How do you view live previews of a SwiftUI view in Xcode 12 Swift Package assuming you have a newly created swift package with another swift package as a dependency?

Note: This may be a bug on Apple's part and if I do not see a response in a few days will file a bug report in feedback assistant.

Live Preview Diagnostics:
Code Block
build aborted due to an internal error: planningFailed("multiple configured targets of \'SwiftyStoreKit\' are being created for iOS Simulator")
---------------------------------------
SchemeBuildError: Failed to build the scheme "TestPackagePreview"
unexpected service error: build aborted due to an internal error: planningFailed("multiple configured targets of \'SwiftyStoreKit\' are being created for iOS Simulator")
Build system information:
error: unexpected service error: build aborted due to an internal error: planningFailed("multiple configured targets of \'SwiftyStoreKit\' are being created for iOS Simulator")


Package.Swift:
Code Block
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
    name: "TestPackagePreview",
    platforms: [
            .iOS(.v13)
        ],
    products: [
        // Products define the executables and libraries a package produces, and make them visible to other packages.
        .library(
            name: "TestPackagePreview",
            targets: ["TestPackagePreview"]),
    ],
    dependencies: [
        .package(url: "https://github.com/bizz84/SwiftyStoreKit.git", .branch("master"))
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages this package depends on.
        .target(
            name: "TestPackagePreview",
            dependencies: ["SwiftyStoreKit"]), // this causes the error in preview, but is needed to use the dependency throughout package.
        .testTarget(
            name: "TestPackagePreviewTests",
            dependencies: ["TestPackagePreview"]),
    ]
)