零依赖的模块资源访问工具:定位 pod 自己的资源 Bundle(CocoaPods resource_bundles / SwiftPM 产物),并提供取图、取色的便捷方法。
CocoaPods:
pod 'YQBundle'SwiftPM:
.package(url: "https://github.com/yuyedaidao/YQBundle.git", from: "0.1.0")在模块内缓存一次资源 Bundle(Bundle.resource(named:) 每次调用都会探测文件系统,不要在渲染路径里直接调):
import YQBundle
extension Bundle {
static let player = Bundle.resource(named: "YQTXPlayer")
}
imageView.image = Bundle.player?.image(named: "button_play")
view.backgroundColor = Bundle.player?.color(named: "player_background")name 传 podspec 里 resource_bundles 的 key,可带可不带 .bundle 后缀。
Bundle.resource(named:) 依次探测以下落点:
| 接入方式 | 资源 Bundle 落点 |
|---|---|
| 静态库 | App.app/<name>.bundle |
| 动态 framework | App.app/Frameworks/<X>.framework/<name>.bundle |
| SwiftPM | App.app/<Package>_<Target>.bundle |
全部未命中时返回 nil。SwiftPM 接入且有资源的 target 也可以直接用系统生成的 Bundle.module,本库不与它重名。
- 只覆盖 iOS(
canImport(UIKit)),Foundation/UIKit 之外无任何依赖。 - 静态库落点分支已实现但未在自动化测试中覆盖。
[email protected], [email protected]
YQBundle is available under the MIT license. See the LICENSE file for more info.