快速创建自己的CocoaPod库

在创建自己的cocoapod库之前,先要确保两件事:1.自己的电脑已经安装了cocoapod。2.确保你要创建的库名别人没有使用过,可以用pod search xxx(库名)来搜索下。
详情可参考官方文档https://guides.cocoapods.org/making/using-pod-lib-create.html

创建本地pod

pod lib create LCTreasureKit

创建本地pod的时候会回答几个问题,按照项目的实际情况回答即可。

//选择什么平台来构建pod
What platform do you want to use?? [ iOS / macOS ]
 //选择什么语言来构建pod
What language do you want to use?? [ Swift / ObjC ]
//是否为你的库生成一个xcode demo
Would you like to include a demo application with your library? [ Yes / No ]
//选择测试框架,如果不知道官方建议选第一个
Which testing frameworks will you use? [ Specta / Kiwi / None ]
//基于试图的测试
Would you like to do view based testing? [ Yes / No ]
//类的前缀
What is your class prefix?

成功创建后,会自动打开项目工程,如下图所示


image.png

创建远端仓库

可以在github、码云等平台,为该pod创建一个远端仓库,这里已github为例:


image.png

绑定远端库

1.进入本地pod项目中,去绑定远端仓库。

git remote add origin httpsUrl

2.然后将本地代码推送到远端仓库

git push -u origin master

修改本地.podspec文件

Pod::Spec.new do |s|
  //名字
  s.name             = 'LCTreasureKit'
//版本
  s.version          = '1.0.1'
  //摘要
  s.summary          = 'Treasure chest for iOS developers.'
  //描述
  s.description      = "This is a collection of commonly used tool classes to help developers develop better."
   //主页
  s.homepage         = 'https://github.com/xxx-xx/LCTreasureKit.git'
  //截图
  # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { 'Xu Lichao' => '[email protected]' }
  //资源,远端库地址
  s.source           = { :git => 'https://github.com/xxx-xx/LCTreasureKit.git', :tag => s.version.to_s }
  # s.social_media_url = 'https://twitter.com/'

  s.ios.deployment_target = '8.0'
  //库里包含的文件
  s.source_files = 'LCTreasureKit/Classes/**/*'
  //bundle资源
  # s.resource_bundles = {
  #   'LCTreasureKit' => ['LCTreasureKit/Assets/*.png']
  # }

  # s.public_header_files = 'Pod/Classes/**/*.h'
  # s.frameworks = 'UIKit', 'MapKit'
//依赖三方库,如果需要多个,则写多行
  # s.dependency 'AFNetworking', '~> 2.3'
  # s.dependency 'MJRefresh', 
  
end

具体详情可参考官网文档https://guides.cocoapods.org/syntax/podspec.html

导入代码

image.png

image.png

把你要新增的代码放到classes文件夹下,然后导入到Kit目录下。
进行git add 、git commit 和git push 三个常规步骤。
代码准备推到pod库的时候,要先打标签,并推送标签

git tag -m "first" "1.0.0" OR git tag 1.0.1
git push --tags

提交Pod

1.注册pod 帐户

pod trunk register yourMail yourName

注册完记得去邮箱激活,激活成功后可以输入pod trunk me 查看pod帐户信息。

2.验证pod

pod lib lint yourKit.podspec

3.提交pod

pod trunk push NAME.podspec
image.png

最后出现congrats信息,那么pod已经提交成功了,可以在其他项目中添加使用该pod。

你可能感兴趣的:(快速创建自己的CocoaPod库)