SPM Resources only in debug configuration

Very excitied to try out SPM resources support!

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?


I have the same question !

1 Like

This isn't supported right now, but sounds like an interesting future direction to explore.

Ah, gotcha! Wondering if there’s at least a workaround to suggest for now.

What if these resources were placed in a separate target? Are there any tricks for conditionally linking two targets between dev and release configurations?

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.

That sounds useful! But I couldn't seem to get it working. It appears that TargetDependencyCondition only supports .when(.platforms), but no .configuration.

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.

Yep, it is, only the platform part is implemented. It was incorrectly updated to fully implemented, let me fix that.

Updated the status to

Partially implemented (Swift 5.3 supports platform conditionals, but not configuration conditionals)


1 Like
Terms of Service

Privacy Policy

Cookie Policy