Draft Proposal: Package Resources

Several people have mentioned a worry about the amount of extra code that would be necessary to support both SwiftPM and another package manager. Basically this is all it is:

#if SWIFT_PACKAGE // ← Or some custom condition passed from the manifest.
let thisTargetResourceBundle = SPMResources.bundle
#else
class BundleIdentifier {}
let thisTargetResourceBundle = Bundle(for: BundleIdentifier.self)
// ↑ The last two lines have always been necessary anyway.
#endif

And then it is used everywhere like this:

let image = UIImage(
    name: "MyIcon",
    in: thisTargetResourceBundle, // ← Voilà.
    compatibleWith: UITraitCollection(userInterfaceStyle: .dark))

Note that Bundle(for: BundleIdentifier.self) is not viable for every kind of product SwiftPM supports, so attempting to use the same strategy as other package managers just to save 4 lines of code per target would be incredibly restricting. (Right now I think it would be possible with exactly none of the existing product types; executable, dynamic library, and static library products are all not bundles. And of course a product can contain multiple targets...)