Generating resource_bundle_accessor, Type 'Bundle' has no member 'module'
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` doesn'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!
AND❗️❗️
Don't forget to build (cmd+b) the code to make the .module
be created!
Swift Package Manager - Type 'Bundle' has no member “module” error
Besides all errors in the test file, the only issue remains is that module
is not an optional
. To fix that, just change this:
public let unimodURL = Bundle.module?.url(forResource: "unimod", withExtension: "XML")
to:
public let unimodURL = Bundle.module.url(forResource: "unimod", withExtension: "xml")
Update:
If you use .xcodeproj
file, you will continue seeing this error. You should consider opening it with the package.swift
or import it as a package (instead of converting it to a project)!
by the way, here is the generated file, so you can add it as a development asset when you are working with the xcodeproject:
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 = "BioSwift_BioSwift"
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 BioSwift_BioSwift")
}()
}
Xcode unittest build failed with error Undefined symbols for architecture x86_64
According to this link, I need to set Bundle Loader
with below content in unittest target Build Settings
$(BUILT_PRODUCTS_DIR)/MyExistingApp.app/MyExistingApp
Why can't code inside unit tests find bundle resources?
When the unit test harness runs your code, your unit test bundle is NOT the main bundle.
Even though you are running tests, not your application, your application bundle is still the main bundle. (Presumably, this prevents the code you are testing from searching the wrong bundle.) Thus, if you add a resource file to the unit test bundle, you won't find it if search the main bundle. If you replace the above line with:
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSString *path = [bundle pathForResource:@"foo" ofType:@"txt"];
Then your code will search the bundle that your unit test class is in, and everything will be fine.
Related Topics
How to Silence a Warning in Swift
The "Prefs" Url Scheme Is Not Working in iOS 10 (Beta 1 & 2)
Propagate an Optional Through a Function (Or Init) in Swift
Select() from Linq in Swift 3.0
How to Use Alamofire with Custom Headers
How to Create a Generic Array Extension That Sums Number Types in Swift
How to Override Trait Collection for Initial Uiviewcontroller? (With Storyboard)
Build Error When Trying to Override an Initializer in Xcode 6.3 Beta 3
Swift Performsegue Going to Xcode
Include Swiftui Views in Existing Uikit Application
Swift - Increment Label With Stepper in Tableview Cell
Troubles With Starting Value Using Uislider
Swiftui - Passing Data from Swiftuiview to Scenekit
How to Create a Fixed-Size Array of Objects