我在如何在cocoapods resource_bundle中加载资源方面遇到了很多困难.
以下是我放在.podspecs文件中的内容.
s.source_files = 'XDCoreLib/Pod/Classes/**/*'
s.resource_bundles = {
'XDCoreLib' => ['XDCoreLib/Pod/Resources/**/*.{png,storyboard}']
}
Run Code Online (Sandbox Code Playgroud)
这就是我想从主项目中做的事情.
let bundle = NSBundle(forClass: XDWebViewController.self)
let image = UIImage(named: "ic_arrow_back", inBundle: bundle, compatibleWithTraitCollection: nil)
print(image)
Run Code Online (Sandbox Code Playgroud)
我确实看到了图片XDCoreLib.bundle,但它返回零.
在 Xcode 11 上,我的 .xcassets 不会在 Xcode 10 上引起任何问题,导致编译失败并显示以下消息:
错误:多个命令产生“/Users/user/Library/Developer/Xcode/DerivedData/project-enjiypsgxtcdbnaripixgtnjlagx/Build/Products/Debug-iphonesimulator/project.app/Assets.car”:1
)目标“项目”(项目“项目” ') 具有输入为 '/Users/user/sandbox/project/Resources/buttons.xcassets' 的编译命令
2) 该命令取决于目标 'project'(项目 'project')中的命令:脚本阶段“[CP] Copy Pods资源”
我能够编译项目的唯一方法是从目标中删除 .xcassets,明显的缺点是它们在构建中不可用。
PS:这发生在 2 个 ObjC 项目中。