Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

swift - Generating resource_bundle_accessor, Type 'Bundle' has no member 'module'

Some times Xcode can not determine the module parameter in the Bundle.

Type 'Bundle' has no member 'module'

My investigations show that SPM generates an extension on the module (some times) for this property automatically in a file called resource_bundle_accessor like:

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 = "ABUIKit_ABStyleKit"

        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 ABUIKit_ABStyleKit")
    }()
}

But sometimes it won't. Why is that and how can I make it work automatically again (Without the need to manually implement that.)

Both situations happen on Xcode 12 beta.3

Update

Sometimes it shows:

'module' is inaccessible due to 'internal' protection level

And it's not showing the file at all.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

SPM generates the resource_bundle_accessor only if the corresponding target contains resources as the argument like:

    .target(
        name: "ChenzookKit",
        dependencies: ["Apollo"],
        resources: [.process("Resources")] // <- `copy` or `process` deson't really matter 
    ),

Also, note that it should be a valid resource path.

AND??

The project MUST actaully contains Resources inside the target's Directory!

Example

AND????

Don't forget to build (cmd+b) the code to make the .module be created!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...