Search code examples
iosxcodebundleswift-package-managerxcframework

Creating Swift Package from XCFramework: should .bundle be part of xcframework?


I'm trying to create a swift package from xcframework, the question is if the framework need to load certain resources from a .bundle file, should the bundle be part of the framework, ie. xcframework? I had the following files in the single zip file:

MyPackage.xcframework
MyPackage.bundle

And uploaded it to a host server, in my Package.swift:

targets: [
        .binaryTarget(name: "MyPackage", url: "HOST/MyPackage.xcframework.zip", checksum: "CHECKSUM")
    ]

I can add the Swift Package to my project and use it, but at runtime it cannot find the .bundle file.

I found someone having the same problem: https://devforum.zoom.us/t/bundling-the-zoom-sdk-within-a-swift-package/48400

Even having the .bundle file as dependency in the Package.swift, it doesn't work, unless the bundle file is manually copied into the project.

So my question is, should this bundle be part of the .xcframework file instead of being a standalone .bundle file along with the .xcframework file? Or if there's something else I can do?

Thanks!


Solution

  • You can use the new approach introduced in Swift 5.3 for bundling resources with your swift package as described here.

    Currently, there are two rules that are supported: process rule and copy rule, process rule applies specific processing rules to your resource files depending on whether it is xib, storyboard etc.

    In your case, you need to use copy rule to copy the .bundle resource in your app. By default copy rule will copy your file to the root directory of your app, you can decide to provide path to a folder instead if you want to copy your file with specific folder structure.