【发布时间】:2020-08-03 21:46:36
【问题描述】:
有时 Xcode 无法确定 Bundle 中的module 参数。
类型“Bundle”没有成员“模块”
我的调查表明,SPM 会在名为 resource_bundle_accessor 的文件中自动为该属性在模块上生成一个扩展名(有时),例如:
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 = "ABUIKit_ABStyleKit"
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 ABUIKit_ABStyleKit")
}()
}
但有时不会。为什么会这样以及如何使其再次自动运行(无需手动实现。)
这两种情况都发生在 Xcode 12 beta.3
更新
有时会显示:
“模块”由于“内部”保护级别而无法访问
而且它根本没有显示文件。
【问题讨论】:
-
这个 resource_bundle_accessor 文件在哪里?我尝试了答案中建议的所有内容,但它不起作用。不如自己创造吧。
-
不,你不能自己创建它!!!它是自动生成的,这是问题的重点。
-
我今天早上实际上在这里发布了一个相关问题:stackoverflow.com/questions/64403646/… - 也许您可以在我的
Package.swift文件中发现错误?
标签: swift xcode bundle swift-package-manager