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:

CoreUnit.xctest/Contents/Resources/Firebase_CoreUnit.bundle/Contents/Resources/GoogleService-Info.plist

vs

FirebaseCore-Unit-unit.xctest/GoogleService-Info.plist

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

Thanks.

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.

2 Likes

Thanks Karl! That worked well for me.

For implementation details see Turn on ABT unit tests with SPM by paulb777 ¡ Pull Request #6016 ¡ firebase/firebase-ios-sdk ¡ GitHub

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.