Playgrounds in Swift Package with resources

When I try to use a playground in my swift package I get the following error:

Fatal error: unable to find bundle named swift-my-package_MyStruct: file MyStruct/resource_bundle_accessor.swift, line 27

The (generated) code looks like this:

import class Foundation.Bundle

private class BundleFinder {}

extension Foundation.Bundle {
    /// Returns the resource bundle associated with the current Swift module.
    static var module: Bundle = {
        let bundleName = "swift-my-package"

        let candidates = [
            // Bundle should be present here when the package is linked into an App.
            Bundle.main.resourceURL,

            // Bundle should be present here when the package is linked into a framework.
            Bundle(for: BundleFinder.self).resourceURL,

            // For command-line tools.
            Bundle.main.bundleURL,
        ]

        for candidate in candidates {
            let bundlePath = candidate?.appendingPathComponent(bundleName + ".bundle")
            if let bundle = bundlePath.flatMap(Bundle.init(url:)) {
                return bundle
            }
        }
        fatalError("unable to find bundle named swift-my-package")
    }()
}

There's no case for playground. Is that intentional?
How do I make it work in a playground?

1 Like