In order to bring the discussion around Swift PM, Bundles and Resources forward (see also the related bug report SR-2866) and since I'm not really happy with the approach taken within Anders Bertelrud's draft proposal where we would basically simply place resources into existing targets and reference them via
Bundle.moduleResources.path(forResource: "MyInfo", ofType: "plist"), I took some time to write an alternate proposal:
While it's definitely not yet complete (e.g. the entire "detailed design" section is missing) and I'm also not completely happy with the design myself, I feel like it already gets through the basic idea:
Using a more type-safe approach with some built-in types supported for free but flexible enough to be extended for supporting any (custom) type. The draft proposes a new target type (
resourceTarget) to do that which is not necessarily required though to allow type-safe access to resources. Someone else could write a draft based off of mine which could get rid of the new target type. This is only intended as a starting point for further discussions, so feel free to express your thoughts of any kind or propose new ideas, which we might then use together to improve upon the proposal or write a new one.
Here are some things I personally think should be tackled by resources support in SwiftPM:
- allow type-safe access with resource availability check from the compiler, preventing dynamic strings (removing the need for tools like SwiftGen entirely)
- allow folder-based types for different contexts, e.g. to make it possible to initialize different
UIImageresources from a .xcassets folder or a
Stringfrom a directory containing .lproj folders
My proposal only solves the first requirement. That's what I'm planning to work on in an update of the proposal. What other goals do you have in mind that could be solved by SwiftPM's resources support?