Loading resources from SPM Package

Hi,

I have a SPM Library where I add some resources.
But I can't load them within the package because I got this error.

Type 'Bundle' has no member 'module'

Am I missing something ?

I'm using Xcode 12.
I add the ressource this way in the Package.swift file

Code Block
.target(
name: "MyPackage",
resources: [.copy("Mocks")]
),

Are you using Xcode or swift build to build the package?
I have the same issue. I am using Xcode (Version 12.0 beta 2 (12A6163b)).

Added a resources: [.copy("something.json")] in Package.swift as well. And that referenced file on the same level as the Readme.

Code Block
Type 'Bundle' has no member 'module'


PS: There is no failure if I reference a file in the Package.swift file that is actually not added. Like resources: [.copy("file/that/does/not/exist")]. Is it supposed to be like this?
Thank you unknown Developer Tools Engineer, swift build works. But why Bundle.module doesn't work? Documentation suggests to use Bundle.module for resources. Looks like it's not available in current Xcode-Beta. When it will be available?
I've found out that if you don't generate Xcode Project file for the package but open package folder with Xcode instead there are no errors with Bundle.module and you even can see generated code for searching your module resources by CTRL+CMD+Click on .module.
To build an iOS package from command line you can use this command uses the iOS 14 SDK:

swift build -Xswiftc "-sdk" -Xswiftc "`xcrun --sdk iphonesimulator --show-sdk-path`" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios14.0-simulator"

Okay I also found a solution, so Swift actually generates the Bundle.module file 🎉

The documentation explicitly states that you have to put your Resources under the folder <project_root>/Sources/<MyTarget>/ since SPM scopes resources by target. The target definition looks then like this for my repo SHSearchBar (compare file structure on Github):

Code Block swift
// swift-tools-version:5.3
import PackageDescription
targets: [
.target(
name: "SHSearchBar",
resources: [.copy("Resources")]
)
]

Target Folder: <project_root>/Sources/SHSearchBar
Resource Folder: <project_root>/Sources/SHSearchBar/Resources

To make my little post here complete I also want to mention that a package using the Bundle.module approach can be integrated in apps that run on iOS <14 too since the generated extension does not contain any new API 👍
Loading resources from SPM Package
 
 
Q