组件化第一步,建立私有Pod

更好的阅读体验,欢迎访问个人博客html

关于组件化,目前比较流行的方案大概有三种:Router, Protocol, Target-Action。 不管是选择哪种方案,都须要经过创建私有Pod来管理项目。本文但愿经过创建一个组件化中经常使用的Base库能将这个事情讲清楚。ios

建立Pod

建立Base库的podspec

选择合适的本地路径建立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

编辑podspec

用编辑器打开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
复制代码

测试podspec是否正确

cd Base
pod lib lint
复制代码

建立仓库(Repository)

私有库也须要单独一个Repository来存储咱们的代码,就像RxSwfit
此处用Github的私有库为例,通常建立在公司的GitLab上。
编辑器

关联本地与远端,提交代码

经过如下命令将远端仓库与本地代码关联起来

git remote add origin https://github.com/Wrapperss/Base.git
git push -u origin master
复制代码

提交代码,并将打上Tag

注意:Tag必须与以前在podspec中填写的version一致,这里咱们是0.0.1 ide

建立私有的Spces

建立一个私有的仓库

将私有Spces建立到本地

pod repo add WSpecs https://github.com/Wrapperss/WSpecs.git
复制代码

查看本地中open ~/.cocoapods/repos
repos中两个文件夹(Master,WSpces),其中中WSpces就是咱们新建立的。组件化

将Pod推到到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' #可使用私有库了!
复制代码
相关文章
相关标签/搜索