Bug: Xcode 26.2 wants `ENABLE_DEBUG_DYLIB`: How do I enable that in `Package.swift`?

Xcode tells me

Previewing in executable targets now requires a new build layout for unoptimized builds. Either set ENABLE_DEBUG_DYLIB to YES for this target, or break out your preview code into a separate framework with its own scheme.

How do enable that in Package.swift. swiftSettings don't work (.define and unsafeFlags with -D ...).

Creating a library product that the executable then depends on doesn't help either.

I have two targets, one is an executable target. The #Preview macro is in the non-executable target.

Answered by Frameworks Engineer in 896765022

Unfortunately, SwiftPM does not inherit Xcode's build settings at all from a containing project. And there is no way to specify any Xcode build setting in a package manifest.

Specifying an executable target with SwiftUI in a package is an interesting case. If I were in your shoes, I'd just pull everything out into another module target in the package and have the executable depend on it. Previewing in that module will work just fine. All the executable needs is the @main entry point. It doesn't need the views or previews to be in that target.

Xcode Version 26.2 (17C52), macOS Sequoia 15.7.3, using toolchain bundled with Xcode.

ENABLE_DEBUG_DYLIB is an Xcode-only build setting. It's something that controls how Xcode builds app bundles. It's not a compiler flag. You don't need it for Swift package manifests because app bundles are not defined in Package.swift manifests.

Are you running into specific issues?

I have an executable SwiftUI target in my swift package, and have run into this error also - Previews requires ENABLE_DEBUG_DYLIB=YES to be defined. currently my package.swift has this: .executableTarget( name: "ColorPickerDemo", dependencies: ["ColorPicker"], path: "Sources/ColorPickerDemo", swiftSettings: [ .enableUpcomingFeature("ApproachableConcurrency"), .define("ENABLE_DEBUG_DYLIB") ], linkerSettings: [ .unsafeFlags([ "-Xlinker", "-sectcreate", "-Xlinker", "__TEXT", "-Xlinker", "__info_plist", "-Xlinker", "Sources/ColorPickerDemo/Info.plist", ]), ] together with an info.plist for the executable, and the demo swiftui app can be launched. Clearly that isn't enough for previews though.. Any ideas?

Unfortunately, SwiftPM does not inherit Xcode's build settings at all from a containing project. And there is no way to specify any Xcode build setting in a package manifest.

Specifying an executable target with SwiftUI in a package is an interesting case. If I were in your shoes, I'd just pull everything out into another module target in the package and have the executable depend on it. Previewing in that module will work just fine. All the executable needs is the @main entry point. It doesn't need the views or previews to be in that target.

Bug: Xcode 26.2 wants `ENABLE_DEBUG_DYLIB`: How do I enable that in `Package.swift`?
 
 
Q