9

I'm using Xcode 12 beta 2. I've packaged my libraries in Swift Packages. DataModel that appear in the error message is one of them, that my current package, WeatherView depends on.

I can build the package fine, but Swift UI preview fails
enter image description here

build aborted due to an internal error: planningFailed("multiple configured targets of \'DataModel\' are being created for iOS Simulator")

----------------------------------------

SchemeBuildError: Failed to build the scheme "WeatherView"

unexpected service error: build aborted due to an internal error: planningFailed("multiple configured targets of \'DataModel\' 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 \'DataModel\' are being created for iOS Simulator")
2
  • Trying deleting your derived data. It worked for me. Commented Nov 30, 2020 at 10:31
  • I lost an hour on something similar, but my case was because Xcode 12.4 opened instead of 12.5. After opening the right version, Preview got back to work. Commented Jul 19, 2021 at 21:34

2 Answers 2

10

I found out that making the product library "dynamic" (instead of static) made my previews work from inside the package's targets.

let package = Package(
    name: "Modules",
    platforms: [
        .iOS(.v13)
    ],
    products: [
        .library(
            name: "Modules",
            type: .dynamic,
            targets: ["App"]
        ),
    ],
    dependencies: [],
    targets: [
        .target(
            name: "App",
            dependencies: []
        ),
        .testTarget(
            name: "AppTests",
            dependencies: ["App"]
        ),
    ]
)

One must also declare the package's platforms.

Sign up to request clarification or add additional context in comments.

1 Comment

this did the trick for me as well, thanks! Do you know why this is the case?
3

I got this same error when trying to preview my SwiftUI canvas for a view. I had multiple tabs open in Xcode. I closed all the other tabs but the one with my view and my canvas previews started working again.

2 Comments

This actually worked better for me than the accepted answer. Changing package libraries to dynamic created other problems with Xcode previews. Closing the other tab I had open in Xcode fixed the problem.
I had two tabs opened at the same time (additional editor on right). I closed it and preview started working again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.