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")
}()
}
Swift Package Manager with resources compile errors
You missed a ,
after the target
close parentheses:
.target(
name: "BioSwift",
resources: [
.process("Resources/unimod.xml"),
.process("Resources/aminoacids.json"),
.process("Resources/elements.json"),
.process("Resources/enzymes.json"),
.process("Resources/functionalgroups.json"),
.process("Resources/hydropathy.json")
]
), // Here is the missed `,`
Also, you don't need to add files one by one! Instead, you can add a directory:
.process("Resources")
I get the error: Value of type 'Bundle' has no member 'pathForResources'
You are mixing up Swift 2 and 3 code and even in Swift 2 there is no pathForResources
(plural) API.
If you are looking for an URL use the URL related API:
Bundle.main.url(forResource: "Music", withExtension: "mp3")
and the AVAudioPlayer
initializer throws
do {
let url = Bundle.main.url(forResource: "Music", withExtension: "mp3")!
let backgroundAudio = try AVAudioPlayer(contentsOf: url)
} catch {
print(error)
}
In this case you can even write
let url = Bundle.main.url(forResource: "Music", withExtension: "mp3")!
let backgroundAudio = try! AVAudioPlayer(contentsOf: url)
because the initializer will succeed always (if it does not it's a design error).
Edit:
This is a way to create the audio player with a closure
class ViewController: UIViewController {
let backgroundAudio : AVAudioPlayer = {
let url = Bundle.main.url(forResource: "Music", withExtension: "mp3")!
return try! AVAudioPlayer(contentsOf: url)
}()
}
and play the sound
let controller = ViewController()
controller.backgroundAudio.play()
PS: Do not use NS...
classes like NSURL
if there is a native Swift counterpart (URL
)
Related Topics
"Ambiguous Reference to Member Map" When Attempting to Append/Replace Array Element
Extend All Number Types in Swift
Why Is Inceptionv3 Machine Learning Model Not Recognized on My Project
Passing in Variable Number of Args from One Function to Another in Swift
Reading from Txt File in Swift 3
Cell Is Duplicated Multiple Times When Posting to Firebase
How to Write to a Variable from Within The Firebase Getdocument Function (Swift)
Get Applicationdidfinishlaunching Call in a View Controller. Parse Not Initialized Yet
iOS 10 App Crashes When Accessing Camera
Can't Get Throws to Work with Function with Completion Handler
Decoding a Nested Array in Swift 4
A Concise Way to Not Execute a Loop Now That C-Style for Loops Are Going to Be Removed from Swift 3
Apple Watch and iPhone Are Not Connected When The App in Phone Goes to Background
How to Fix Cannot Find 'Firebaseapp' in Scope
Swiftui: What Are The Differences Between Image and UIimage
How to Access The Model Component of Reality Composer in Realitykit