Why resources in Swift Package can not have same name?

What the reason resources in target can not have the same name?

I am trying to add following resources to test target:


And having error:

swift build
error: 'geometrize': multiple resources named 'testRasterize.1.png' in target 'geometrizeTests'
error: ExitCode(rawValue: 1)
[0/1] Planning builderror: 'geometrize': multiple resources named 'testRasterize.1.png' in target 'geometrizeTests'

This is not a bug. There's even a test for checking this behaviour.


Valeriy Van

It seems a can add whole folder recursively without problems:

The resources are copied into the bundle at a flat location in order to work predictably with the Bundle resource methods. Hence the names clash at the destination. If you plan on accessing them some other way, then copy as you have done is the intended method of constructing a custom file tree.

1 Like

I see from documentation why. Resources are copied to top-level of resource bundle. But if path is directory, directory structure is preserved.

/// If your resources must remain untouched or must retain a specific folder
/// structure, use the `copy` rule. It copies resources at the given `path`,
/// as is, to the top level in the package's resource bundle. If the given
/// path represents a directory, Swift Package Manager preserves its structure.