前言
经常使用别人的封装库或者项目,在项目开发中自己也有封装,即使不能给别人广泛使用,也可以自己在多项目中pod方式使用自己封装的代码
前提:mac上已经装好了pod,git
一、创建自己库添加Cocoapods支持
1、基于pod自动创建项目
在终端输入
pod lib create JGCache
提示对应的询问命令
Cloning `https://github.com/CocoaPods/pod-template.git` into `JGCache`.
Configuring JGCache template.
------------------------------
To get you started we need to ask a few questions, this should only take a minute.
If this is your first time we recommend running through with the guide:
- http://guides.cocoapods.org/making/using-pod-lib-create.html
( hold cmd and double click links to open in a browser. )
What language do you want to use?? [ Swift / ObjC ]
> Swift
Would you like to include a demo application with your library? [ Yes / No ]
> Yes
Which testing frameworks will you use? [ Quick / None ]
> None
Would you like to do view based testing? [ Yes / No ]
> No
项目创建成功,并编译成功
2、接下来在https://github.com/官网自己的账号下创建一个仓库JGCache(这里不是重点,不用介绍了)
3、将pod命令自动创建的项目上传到github JGCache项目中,(这里不是重点,不用介绍了)
4、给仓库JGCache 主分支master 创建一个tag 0.1.0 (这里不是重点,不用介绍了)
5、打开项目中的JGCache.podspec文件可以看到默认设置
#
# Be sure to run `pod lib lint JGCache.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'JGCache'
s.version = '0.1.0'
s.summary = 'A short description of JGCache.'
# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!
s.description = <<-DESC
TODO: Add long description of the pod here.
DESC
s.homepage = 'https://github.com/lbj147123@163.com/JGCache'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'lbj147123@163.com' => 'lbj147123@163.com' }
s.source = { :git => 'https://github.com/lbj147123@163.com/JGCache.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.ios.deployment_target = '8.0'
s.source_files = 'JGCache/Classes/**/*'
# s.resource_bundles = {
# 'JGCache' => ['JGCache/Assets/*.png']
# }
# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
end
6、修改项目中的JGCache.podspec文件的设置为(这里就不介绍每一项的意思了)
Pod::Spec.new do |s|
s.name = 'JGCache'
s.version = '0.1.0'
s.summary = 'this is description'
# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!
s.description = <<-DESC
TODO: this is description
DESC
s.homepage = 'https://github.com/Ucself/JGCache'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { '李保君' => 'lbj147123@163.com' }
s.source = { :git => 'https://github.com/Ucself/JGCache.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.ios.deployment_target = '8.0'
s.source_files = 'JGCache/Classes/**/*'
# s.resource_bundles = {
# 'JGCache' => ['JGCache/Assets/*.png']
# }
# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
s.dependency 'ObjectMapper', '~> 3.0.0'
end
7、检测填写的podspec是否有错误,cd进入JGCache文件目录
pod spec lint
8、测试本地导入的文件是否报错。cd 进入项目Example文件路径,导入依赖的第三方库
pod install
9、上传的cocopods管理
pod trunk push JGCache.podspec --allow-warnings
二、更新自己库添加Cocoapods支持
1、JGCache.podspec 文件中你需要更改的项目更改(主要更改版本如:1.0.0)
2、在啊gitbug对你的工程添加标签如1.0.0
3、上传工程工程代码
4、再次执行
pod trunk push JGCache.podspec --allow-warnings
网友评论