为了及时响应市场需求,尽快的做出产品,同时伴随着项目周期的缩短,我们需要手中有足够的"轮子"来应付快速的项目开发,此时我们可以考虑把常用的模块做成pod库来快速的集成模块。当然,出于公司项目的保密性,就要使用私有pod了,今天,就通过实例来看一下,私有pod库应该怎么建立和使用。
1、创建一个私有的版本库,用来保存自己的
podspec
,这里我在Github上创建
2、添加私有的pod版本库到本地(请勿填写我的地址)
命令行执行
pod repo add FelixPodRepo https://github.com/sunyajie0829/FelixPodRepo.git
然后我们就可以看到在本地的repo中多出了我们自己的repo
3、创建一个私有的代码库(Github现已支持私有代码库,并且无需付费),用来保存自己的项目文件,记得添加
License
,选择MIT License
4、把项目
clone到本地
,然后添加自己的代码到仓库中
本节因为我额外依赖了两个库
MJRefresh
、DZNEmptyDataSet
,所以,我现在项目中添加了Podfile
,并且引入了MJRefresh
、DZNEmptyDataSet
两个库,同时进行了pod install
,引入了依赖库的文件。在此之后,我们在当前的项目中添加自己的模块代码,这里,我把自己的代码添加到了项目的
Classes
目录下5、在项目中创建
仓库名.podspec
文件,然后修改信息
命令行cd到刚才的项目中,然后使用pod spec create MyAdditions
创建FelixUIKit.podspec
文件
修改内容如下
#
# Be sure to run `pod spec lint FelixTableView.podspec' to ensure this is a
# valid spec and to remove all comments including this before submitting the spec.
#
# To learn more about Podspec attributes see https://docs.cocoapods.org/specification.html
# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#
Pod::Spec.new do |spec|
# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# These will help people to find your library, and whilst it
# can feel like a chore to fill in it's definitely to your advantage. The
# summary should be tweet-length, and the description more in depth.
#
spec.name = "FelixUIKit"
spec.version = "0.0.3"
spec.summary = "TableView include pull down to refresh ,loading img,empty data img and so on"
# 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!
spec.description = <<-DESC
TableView include pull down to refresh ,loading img,empty data img and so on
DESC
# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Specify the location from where the source should be retrieved.
# Supports git, hg, bzr, svn and HTTP.
#
spec.source = { :git => "https://github.com/sunyajie0829/FelixUIKit.git", :tag => "#{spec.version}" }
spec.homepage = "https://github.com/sunyajie0829/FelixUIKit"
# spec.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"
# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Licensing your code is important. See https://choosealicense.com for more info.
# CocoaPods will detect a license file if there is a named LICENSE*
# Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
#
# spec.license = "MIT"
spec.license = { :type => "MIT", :file => "LICENSE" }
# ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Specify the authors of the library, with email addresses. Email addresses
# of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
# accepts just a name if you'd rather not provide an email address.
#
# Specify a social_media_url where others can refer to, for example a twitter
# profile URL.
#
spec.author = { "Felix" => "sunyajie0829@126.com" }
# Or just: spec.author = "Felix"
# spec.authors = { "Felix" => "sunyajie0829@126.com" }
# spec.social_media_url = "https://github.com/sunyajie0829/FelixTableView"
# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# If this Pod runs only on iOS or OS X, then specify the platform and
# the deployment target. You can optionally include the target after the platform.
#
# spec.platform = :ios
spec.platform = :ios, "10.0"
# When using multiple platforms
# spec.ios.deployment_target = "5.0"
# spec.osx.deployment_target = "10.7"
# spec.watchos.deployment_target = "2.0"
# spec.tvos.deployment_target = "9.0"
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# CocoaPods is smart about how it includes source code. For source files
# giving a folder will include any swift, h, m, mm, c & cpp files.
# For header files it will include any header in the folder.
# Not including the public_header_files will make all headers public.
#
spec.source_files = "FelixUIKit/Classes/*.{h,m}"
# spec.exclude_files = "Classes/Exclude"
# spec.public_header_files = "Classes/**/*.h"
# ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# A list of resources included with the Pod. These are copied into the
# target bundle with a build phase script. Anything else will be cleaned.
# You can preserve files from being cleaned, please don't preserve
# non-essential files like tests, examples and documentation.
#
# spec.resource = "icon.png"
# spec.resources = "Resources/*.png"
# spec.preserve_paths = "FilesToSave", "MoreFilesToSave"
# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Link your library with frameworks, or libraries. Libraries do not include
# the lib prefix of their name.
#
# spec.framework = "SomeFramework"
# spec.frameworks = "SomeFramework", "AnotherFramework"
# spec.library = "iconv"
# spec.libraries = "iconv", "xml2"
# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# If your library depends on compiler flags you can set them in the xcconfig hash
# where they will only apply to your library. If you depend on other Podspecs
# you can include multiple dependencies to ensure it works.
spec.requires_arc = true
# spec.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
spec.dependency 'MJRefresh', '~> 3.1.15.7'
spec.dependency 'DZNEmptyDataSet', '~> 1.8.1'
end
文件内容解释如下
spec.name #pod的名称
spec.version #pod的版本
spec.summary #pod的简介
spec.description #pod的描述
spec.source #pod项目对应的仓库地址
spec.homepage #pod项目的网址
spec.license #pod项目的License文件
spec.author #pod项目的作者
spec.platform #pod项目支持的版本
spec.source_files #pod项目的代码文件
spec.requires_arc #是否启用ARC
spec.dependency #pod项目的依赖库
6、验证
FelixUIKit.podspec
配置是否正确
命令行cd到podspec
文件所在目录,输入pod lib lint --allow-warnings
,如果出现
则代表验证通过
7、推送
FelixUIKit.podspec
到版本库中
命令行执行
pod repo push FelixPodRepo FelixUIKit.podspec --allow-warnings
如果失败,请查看失败信息进行调整。推送成功之后如图所示
然后执行
pod repo update
更新一下信息,更新完毕后执行
pod search FelixUIKit
验证一下是否发布成功
注:因为pod搜索缓存的缘故,在执行
pod search FelixUIKit
的时候,无论如何都搜索不到FelixUIKit
,这个时候可以清空下Cocoapod的搜索结果文件rm ~/Library/Caches/CocoaPods/search_index.json
清除之后可以正常进行搜索。
8、私有Pod的使用
新建pod文件,然后引入私有pod的地址,其他的按照正常的语法进行编写即可
source 'https://github.com/sunyajie0829/FelixUIKit.git'
source 'https://github.com/CocoaPods/Specs.git'
platform:ios,'11.0'
target 'PodRepoTest' do
pod 'FelixUIKit'
end
执行pod install
后就可以正常引入私有pod了。
在现有市场环境的需求下,开发需要紧跟市场的变更脚步,尽可能快的响应需求并及时开发出产品,所以前期的轮子积累非常必要,也建议大家在有时间的时候,尽可能的将自己项目中的模块独立出来,方便以后的项目需求。
以上内容转载请注明出处,同时也请大家不吝你的关注和下面的赞赏
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
网友评论