美文网首页iOS Developer
Swift版cocoapods库制作

Swift版cocoapods库制作

作者: 风清水遥 | 来源:发表于2017-04-13 19:25 被阅读1110次

swift cocoapods

我们都知道iOS项目管理方式pod是一个很好用的工具,可以用来更新管理和更新第三方库资源,下面介绍一下自己上传pod库的方法,下面以FanRefresh为例。

1.项目准备(FanRefresh)

  • 完整的git项目,包含LICENSE,README.md,可以把git clone 或者本地项目上传github上
  • 记得swift项目里面要写好暴露的属性和方法和类,必须使用public或open,不然别人pod下拉不能调用
public enum FanRefreshState:Int {
    case Default=0
    case Pulling=1
    case Refreshing=2
    case WillRefresh=3
    case NoMoreData=4
}
public class FanRefreshComponent: UIView {}
public var scrollViewOriginalInset:UIEdgeInsets?
public extension UIScrollView {}
public let FanRefreshHeaderHeight:CGFloat=60.0
    
  • 下面的所有命令行都是在项目根目录(FanRefresh)下执行(切记)

2.podspec文件制作及验证

1.创建podspec文件

pod spec create FanRefresh
//打开文件编辑,或者用Sublime
vi FanRefresh.podspec

2. podspec文件内容

Pod::Spec.new do |s|

  s.name         = "FanRefresh"
  s.version      = "0.0.3"
  #主要标题
  s.summary      = "a swift Refresh control"
  #详细描述(必须大于主要标题的长度)
  s.description  = <<-DESC
       一个swift的下拉刷新,上拉加载库,UITableview,UICollectionView,UIWebView
                   DESC
  #仓库主页
  s.homepage     = "https://github.com/fanxiangyang/FanRefresh"
  s.license      = "MIT"
  s.author       = { "fanxiangyang" => "fqsyfan@gmail.com" }
  s.platform     = :ios,'8.0'
  #仓库地址(注意下tag号)
  s.source       = { :git => "https://github.com/fanxiangyang/FanRefresh.git", :tag => "#{s.version}" }
  #这里路径必须正确,因为swift只有一个文件不需要s.public_header_files
  #s.public_header_files = "Classes/*.h"
  s.source_files = "Classes/*.swift"
  s.framework    = "UIKit","Foundation"
  s.requires_arc = true
end

可以参考FanRefresh.podspecFanKit.podspec子文件夹配置

3.验证FanRefresh.podspec文件正确性

pod lib lint 验证比较严格,或用 pod spec lint

如果出现错误按照错误提示修改,直到终端出现验证通过

fanxiangyang@fanFan FanRefresh$pod lib lint

 -> FanRefresh (0.0.3)

FanRefresh passed validation.
fanxiangyang@fanFan FanRefresh$

3.提交代码到git仓库

1.提交修改的代码和配置到git

git add .
git commit -m "version 0.0.3"
git push origin master

2.打标签提交标签

git tag 0.0.3
git push --tags

3.其他标签命令(可选操作)

git tag   //查看标签
git tag 0.0.3  //把当前代码状态打上标签  
git tag -d 0.0.3 //删除本地标签  
git push origin —delete tag 0.0.3 //删除远程标签

4.上传到cocoapods仓库

1.首次上传pod,注册trunk

pod trunk register fqsyfan@gmail.com 'fanxiangyang'

验证邮件连接通过后,查看信息

2.查看本机tunk信息

pod trunk me

3.提交到spec

pod trunk push FanRefresh.podspec

4.验证是否成功

//如果有该库的信息说明,说明上传成功
pod trunk info FanRefresh

pod search FanRefresh  //pod 查询库

//如果查找不到,更新本地spec仓库 
pod setup  //或者下面的方法
pod repo update
//如果还是查不到:清空搜索缓存
rm ~/Library/Caches/CocoaPods/search_index.json  

5.trunk其他操作(可选)

  • pod trunk delete FanRefresh 0.0.3删除远程提交的pod库
  • Pull requests方式上传的 旧库认领地址
  • $ pod trunk add-owner FanRefresh other@cocoapods.org 添加其他成为组件所有者

5.Like

相关文章

网友评论

    本文标题:Swift版cocoapods库制作

    本文链接:https://www.haomeiwen.com/subject/eimbattx.html