I was wondering if there was any way to exclude certain assets from the release configuration of a package? I was hoping to exclude my “Preview Assets.xcassets” catalog.
The exclude option seemed promising, but there doesn’t appear to be a way to condition it. I don’t think you can use #if DEBUG in a Package.swift. Is there anything like BuildSettingCondition, but for resources?
If you put them in a separate target and forward them with public accessors, then the main target could put #if DEBUG around the import, and use dependencies: [.target(..., condition: .when(configuration: .debug))] in the manifest to prevent it from being included in the product.
Interesting. I hadn’t tried it myself. I copied and pasted from the text of SE‐0273. Maybe its implementation is incomplete? Or it was accepted with revisions that never made it back into the document? @NeoNacho was review manager.
This post outlines a use case that I'm also actively seeking: The ability to share stub-like data between tests in a package and Xcode previews in an app -- without having to include that said data in release builds.
Here is another +1 for this functionality. I am working on a project that is divided in many self-contained SPM packages. I’d like to have fully-featured SwiftUI previews in the packages, with some resources as part of the package, that would be included only in a debug build for SwiftUI previews. Couldn’t find a way to do this currently (as of May 2022).