前俩天公司项目准备使用carthage替代cocoaPods的部分集成第三方库的功能,我就去了解了一下carthage这个去中心化管理三房库的库
我们在用别人的库的时候,因为最近看了些组件化方面的东西,不过都好像是用cocoaPods去实现,于是百度了一下,发现carthage这个工具相对比较简单易用,于是自己动手实现了一下, 步骤如下:
1.创建一个动态库,carthage只支持iOS8以后的动态framework,打开XCode command + n新建工程选择Cocoa Touch Framework 点击next 命名TestFramework


2. 打开工程, 展开products目录下面的framework是红色的, 编译一遍就好了

我用的是swift3.0, 新建一个 test.swift文件, 此处测试用, 随便写了一个方法, class func 声明的时候一定要加上关键字public 要不用不了

把test.swift对外暴露,在这个文件你写方法, 给外界调用, 如果你有不想给外面看的就不要拖进去了

然后共享你的schemes


到此处基本做好了准备工作然后,终端cd 到文件目录下面执行 carthage build --no-skip-current

打开你的文件目录会多了一个carthone文件, 里面有二进制的framework了
接下来就是把你的TestFraemwork传的github上面去, 在github上面新建一个repositories仓库命名TestFramework


github不熟悉的可以去网上找找 利用图中的第一种方式把这个仓库clone到本地步骤如下,在本地新建一个文件夹命名Test 终端cd 到文件目录下把上面的echo"#..........几行命令复制到终端回车即可, 执行完后把刚创建的 TestFramework 文件夹拖到Test目录下, 执行命令
终端输入 git add TestFramework
git commit -m "TestFramework"
git push
完成github就会有你新建的TestFramework代码
最后版本的标记
git tag 1.0.0
git push --tags
到这里自建的framework传到github, 下面检查是否可用
新建一个工程cd 文件目录, thouch cartfile新建文件
在cartfile文件输入你 framework在github上的位置 github"givejun/TestFramework"然后保存,在终端输入 carthage update TestFramework --platform iOS


一定要有tags
终端执行完成后打开project, 导入TestFramework,就可以验证
我就不验证了!
网友评论