更好的阅读体验,欢迎访问个人博客html
关于组件化,目前比较流行的方案大概有三种:
Router
,Protocol
,Target-Action
。 不管是选择哪种方案,都须要经过创建私有Pod来管理项目。本文但愿经过创建一个组件化中经常使用的Base库能将这个事情讲清楚。ios
选择合适的本地路径建立modularization
文件夹 其中的podspec包含了这个库的信息(包括名称,版本和描述等).
下面是官方定义:git
A specification describes a version of Pod library. It includes details about where the source should be fetched from, what files to use, the build settings to apply, and other general metadata such as its name, version, and description.
一个描述各个版本Pod库的规范。它包括关于应该从何处获取源码、使用到的文件、应用构建设置以及其余通用元数据(如其名称、版本和描述)的详细信息。github
cd Base
pod lib create Base
复制代码
建立时会须要回答几个问题 ruby
用编辑器打开Base.podspec
文件,把咱们库的信息填写到podspec
中去。
务必每一项都要填写正确,如s.homepage,s.source中的连接要可以正常访问app
Pod::Spec.new do |s|
s.name = 'Base'
s.version = '0.0.1' # 这里的version要与git操做中的tag相一致,由于目前Base库中尚未代码,故此我把version设为0.0.1
s.summary = 'iOS组件化中Base组件:主要存放项目中无关业务的基础组件'
s.description = <<-DESC TODO: Add long description of the pod here. DESC
s.homepage = 'https://github.com/Wrapperss/Base.git'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Wrappers' => 'zhanglive@outlook.com' }
s.source = { :git => 'https://github.com/Wrapperss/Base.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.ios.deployment_target = '8.0'
s.source_files = 'Base/Classes/**/*'
# s.resource_bundles = {
# 'Base' => ['Base/Assets/*.png']
# }
# s.public_header_files = 'Pod/Classes/**/*.h'
s.frameworks = 'UIKit', 'MapKit'
s.dependency 'AFNetworking', '~> 2.3' #依赖的其余库
end
复制代码
cd Base
pod lib lint
复制代码
私有库也须要单独一个Repository
来存储咱们的代码,就像RxSwfit。
此处用Github的私有库为例,通常建立在公司的GitLab上。
编辑器
git remote add origin https://github.com/Wrapperss/Base.git
git push -u origin master
复制代码
注意:Tag必须与以前在podspec中填写的version一致,这里咱们是0.0.1 ide
pod repo add WSpecs https://github.com/Wrapperss/WSpecs.git
复制代码
查看本地中open ~/.cocoapods/repos
在repos
中两个文件夹(Master,WSpces),其中中WSpces就是咱们新建立的。组件化
pod repo push WSpecs Base.podspec
复制代码
在Podfile
中加入测试
source 'https://github.com/CocoaPods/Specs.git' #公开的
source 'https://github.com/Wrapperss/WSpecs.git' #私有的
pod 'Base', :git=>'https://github.com/Wrapperss/Base.git' #可使用私有库了!
复制代码