Finding Swift Package Manager Resources

I'm seeing that a resource bundled with Swift Package Manager is buried deep within the bundle and doesn't get found by the pathForResource API:




for a CocoaPods resource bundle.

The call here finds the CocoaPods resource but not the Swift Package Manager resource.

What is the proper way to find SwiftPM resources? Is there a way to make the SwiftPM resource bundling compatible with CocoaPods flat bundling?

Intended access to resources works like this.

As for supporting multiple build tools side‐by‐side, this post shows roughly what you’d need to do, although it is from before some of the details were finalized, so you’ll have to mentally swap in bits from the actual finalized syntax from the other link.

1 Like


That doesn't seem to cover the case of injecting a resource from a test target without touching the library code itself.

I'll see what I come up with starting from your links ....

Is there a recommended way to access resources defined in a Package.swift from Objective C? I don't see anything like module on NSBundle.

Create an Obj-C visible API to access Bundle.module.

Yes, the build system defines the SWIFTPM_MODULE_BUNDLE macro to access the module bundle.


Thanks Karl! That worked well for me.

For implementation details see

1 Like

Anyone finding that SWIFTPM_MODULE_BUNDLE doesn't exist in Xcode 12.5 beta?

I found that Xcode 12.5 beta doesn't support symlinked resource files (maybe because they lived outside the package root?) which caused the copy resources in the SPM package definition to not find the resource files, which makes SPM not generate the SWIFTPM_MODULE_BUNDLE macro.

Terms of Service

Privacy Policy

Cookie Policy