Previews for SwiftUI views in Packages don't work in Xcode 26.4

I have an iOS project based on SwiftUI in which almost all code is organised in Packages.

With Xcode 26.2 and 26.3, I can preview all SwiftUI views without issues.

With Xcode 26.4, the same previews don't work, in the canvas appears this error message: "Cannot preview in this file. Could not find target description for “TaskListView.swift”".

The explanation is: "The list of source files that produce object files did not contain this file to be previewed.

Check to make sure it is not excluded using the EXCLUDED_SOURCE_FILE_NAMES build setting."

If I add a SwiftUI view to the main project files (not in a package), the preview works as expected.

Is it an Xcode 26.4 regression? Or do I need to modify some configuration file?

Hi,

Sorry to hear you are having problems getting previews working. The issue you are hitting here sounds like one we are actively looking at. If you want us to check for certain then the best next step will be to file a feedback with diagnostics so we can take a look.

We will need the diagnostics Xcode Previews generates in order to make sure we understand the error the previews system is encountering.

Install the logging profile using instructions available here: https://developer.apple.com/bug-reporting/profiles-and-logs/?name=swift On your mac running Xcode.

Install the logging profile using the following instructions on your mac running Xcode: https://developer.apple.com/bug-reporting/profiles-and-logs/?name=swift

Then when you reproduce the problem in Xcode:

  1. Either (a) an error banner will appear, click the "Diagnostics" button in that banner; or (b) if you're not seeing an error but you still want to provide diagnostics you can get the same diagnostics window by going under the Editor menu in the menu bar, then selecting the Canvas submenu, then selecting "Diagnostics".
  2. In the sheet that appears, click "Generate Report" in the bottom left of the sheet
  3. Attach (or make from the folder) the resulting zip file to the bug (will be named something like previews-diagnostics-0123456789.zip)
  4. Generate a sysdiagnose on your mac and any on-device preview devices, and attach those too

I was able to replicate this issue in a very simple way, within a new project created with the standard Xcode template, to which I added a Swift Package as a library (MyLibrary).

This is the Package definition:

// swift-tools-version: 6.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "MyLibrary",
    platforms: [.iOS(.v18)],
    products: [
        // Products define the executables and libraries a package produces, making them visible to other packages.
        .library(
            name: "MyLibrary",
            targets: ["MyLibrary"]
        ),
    ],
    targets: [
        // Targets are the basic building blocks of a package, defining a module or a test suite.
        // Targets can depend on other targets in this package and products from dependencies.
        .target(
            name: "MyLibrary",
            path: "Sources/MyLibrary"
        ),

    ],
    swiftLanguageModes: [.v6]
)

If the target name is equal to library name (MyLibrary) the preview of SwiftUIView works as expected. If I change the target name (for example MyLibrary1), the preview does not work any longer.

The Diagnostics dialog reports that: == PREVIEW UPDATE ERROR:

GroupRecordingError

Error encountered during update group #64

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

|  NoBuiltTargetDescriptionFoundForTranslationUnit: Could not find target description for “SwiftUIView.swift”
|  
|  The list of source files that produce object files did not contain this file to be previewed.
|  
|  Check to make sure it is not excluded using the `EXCLUDED_SOURCE_FILE_NAMES` build setting.
|  
|  sourceIdentifier: file:///Users/fabiani/Projects/Test/xcode/Test1/MyLibrary/Sources/MyLibrary/SwiftUIView.swift -> SwiftUIView.swift
|  builtTargetDescriptions:
|  static-MyLibrary1

We have submitted a feedback https://feedbackassistant.apple.com/feedback/22366544 as well

Previews for SwiftUI views in Packages don't work in Xcode 26.4
 
 
Q