前言
上一篇总结了cocospod关于私有库的创建,今天总结一下关于私有库更新、文件及资源文件的使用。以下完全个人使用过程的记录,有不对的希望各位大牛给我指点。
一、文件管理
保持原配置
s.source_files = 'SyFileTest/Classes/**/*'
二、资源文件
1、创建bundle文件
因为在私有库中需要通过Bundle读取资源文件,所以在Assets文件下创建bundle文件,终端cd到Example项目,pod install,bundle文件自动进入项目里面
在里面添加私有库需要的图片等文件
2、资源文件配置
s.resource = 'SyFileTest/Assets/SyFileTest.bundle'
3、文件的读取
直接上代码
class BundleLoader: NSObject {
class func imageNamed(name: String, type: String) -> UIImage?{
guard let bp = Bundle(for: self).path(forResource: "SyFileTest", ofType: "bundle") else {
return nil
}
let bundle = Bundle(path: bp)
if let imgp = bundle?.path(forResource: name, ofType: type) {
return UIImage(contentsOfFile: imgp)?.withRenderingMode(.automatic)
}
return nil
}
}
调用代码
BundleLoader.imageNamed(name: "icon_red_start@3x", type: "png")
注意:name需要传全文件名,@3x不能少
完美加载出资源
三、更新
1、将以上修改,提交到远程仓库,不是索引分支(默认分支),提交到专门存放代码那个分支即可,同样要打标签,与版本好一致,记得修改版本好,记得修改版本好,记得修改版本好
s.version = '1.0.2'
其他描述同样是根据实际需求配置
2、代码提交完毕后,也远程验证一下
-> SyFileTest (1.0.2)
- WARN | summary: The summary is not meaningful.
- WARN | description: The description is shorter than the summary.
- NOTE | xcodebuild: note: Using new build system
- NOTE | xcodebuild: note: Building targets in parallel
- NOTE | xcodebuild: note: Using codesigning identity override: -
- NOTE | [iOS] xcodebuild: note: Planning build
- NOTE | [iOS] xcodebuild: note: Constructing build description
- NOTE | [iOS] xcodebuild: warning: Skipping code signing because the target does not have an Info.plist file and one is not being generated automatically. (in target 'App' from project 'App')
Analyzed 1 podspec.
SyFileTest.podspec passed validation.
3、验证完成后,同样提交到远程端私有索引库,即可。
pod repo push SyFileTest SyFileTest.podspec --allow-warnings
Validating spec
-> SyFileTest (1.0.2)
- WARN | summary: The summary is not meaningful.
- WARN | description: The description is shorter than the summary.
- NOTE | xcodebuild: note: Using new build system
- NOTE | xcodebuild: note: Building targets in parallel
- NOTE | xcodebuild: note: Using codesigning identity override: -
- NOTE | [iOS] xcodebuild: note: Planning build
- NOTE | [iOS] xcodebuild: note: Constructing build description
- NOTE | [iOS] xcodebuild: warning: Skipping code signing because the target does not have an Info.plist file and one is not being generated automatically. (in target 'App' from project 'App')
Updating the `SyFileTest' repo
Adding the spec to the `SyFileTest' repo
- [Update] SyFileTest (1.0.2)
Pushing the `SyFileTest' repo
至此,私有库创建、发布、文件、资源文件及更新已经全部完成。后面将开始组件化研究和学习。