最近工作需要做framework,遇到一些问题做下记录。
用swift语言创建framework,在创建2个target(swift,oc)做测试用。如下图
一、制作framework时注意的问题
写1个Class测试用
open class TestClass: NSObject {
@objc open func test1(){
print(#function)
}
}
在oc调用swift的framework的时候,要引入库的桥接文件xxxx-Swift.h例如:
#import <STestFm/STestFm-Swift.h>
只有方法添加@objc的时候oc才能找到方法。
二、创建仓库
切换到项目目录下,在终端上
pod spec create STestFm
就会生成STestFm.podspec文件。
编辑STestFm.podspec文件。
Pod::Spec.new do |spec|
spec.name = "STestFm"
spec.version = "0.0.1"
spec.summary = "STestFm的概要说明"
spec.description = <<-DESC
STestFm的描述
DESC
spec.homepage = "远程仓库地址"
spec.license = "MIT"
spec.ios.deployment_target = '8.0'
spec.author = { "yhl" => "753597827@qq.com" }
spec.source = { :git => "远程仓库地址.git", :tag => "#{spec.version}" }
spec.source_files = "Classes", "STestFm/*.{swift}"
spec.swift_version = '4.2'
end
swift的framework一定要加spec.swift_version字段。
把代码托管在github上,并创建一个0.0.1的tag
验证podspec文件是否正确
pod lib lint --allow-warnings
验证通过
三、上传
查看trunk用命令
pod trunk me
如果没有trunk需要注册
pod trunk register 邮箱 名字
如果多人维护,添加其他维护者
pod trunk add-owner 项目名 邮件
上传
pod trunk push STestFm.podspec --allow-warnings
四、私有库
pod repo add 项目名字 仓库地址
pod repo push xxx xxx.podspec --allow-warnings --sources=仓库地址
五、有修改
如果有修改把原先的tag删掉,重新打个tag,在修改下podspec(必须修改)文件,重新pod repo push就好了。