Swift Package: Fatal error: unable to find bundle named

Swift Package: Fatal error: unable to find bundle named

我有一个 Swift 包,用于我想在多个应用程序中使用的小功能。我只想在使用它的应用程序的 Swift 包中显示 ViewController。

在 Swift 包中,我有这个扩展来获取视图控制器:

    public extension UIViewController{ 
    static func getStoryboardVC() -> UIViewController { 
      let storyboard = UIStoryboard(name: String(describing: self), bundle: Bundle.module) 
        return storyboard.instantiateInitialViewController()! 
    }  
}

Swift 包称为 ARMMap,它有 ARCameraVC 视图控制器,在应用程序中我展示了 SP 的视图控制器,如下所示:

     let vc = ARMap.ARCameraVC.getStoryboardVC()  
 present(vc, animated: true, completion: nil)

这在 Xcode 构建到设备中时效果很好,但是当将应用程序安装为 .ipa 文件或提交到 App Store 时,它​​会崩溃,并出现设备日志中的错误:

Fatal error: unable to find bundle named ARMap_ARMap: file ARMap/resource_bundle_accessor.swift, line 27

获取故事板时 Bundle.model 出现问题。

编辑: 这是自动生成的 resource_bundle_accessor.swift 将 return Bundle.module 以及错误的来源:

    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 = "ARMap_ARMap"

        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 ARMap_ARMap")
    }()
}

这是包清单

    import PackageDescription

let package = Package(
    name: "ARMap",
    products: [
        .library(name: "ARMap", targets: ["ARMap"]),
    ],
    dependencies: [
    ],
    targets: [ 
        .target(
            name: "ARMap",
            dependencies: [],
            path: "Sources/ARMap",
            resources: [.process("Resources")]
        ),
        .testTarget(
            name: "ARMapTests",
            dependencies: ["ARMap"]),
    ]
)

包结构如下:

我认为这是 Xcode 中的错误。我最终删除了模块并从头开始创建它。错误消失了。