目前iOS组件化常用的解决方案是Pod+路由+持续集成,通常架构设计完成后第一步就是将原来工程里的模块按照架构图分解为一个个独立的pod工程(组件),今天我们就来看看如何创建一个Pod私有库。
新建:pod lib create假设我们需要创建的库名为TestLib,下面我们使用Pod官方提供的创建模板:
首先进入我们的工作目录,如workspace,输入命令 pod lib create TestLib 创建过程中需要填写几个问题,如下图所示,按个人所需填写:到这里使用Pod新建一个私有库就完成了。
验证: pod lib lint (podspec配置文件说明)新建完成后,我们还需要验证,需要修改配置文件,通过下面的截图路径找到新建的私有库的配置文件:
或者在Xcode里的:
文件内容:
# # Be sure to run `pod lib lint TestLib.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 https://guides.cocoapods.org/syntax/podspec.html # Pod::Spec.new do |s| # 名称、版本号、概述 s.name = 'TestLib' s.version = '0.1.0' s.summary = 'A short description of TestLib.' # 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 # 主页、截图、license证书、作者信息、源代码地址、社交地址 s.homepage = 'https://github.com/xxx/TestLib' # s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2' s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { 'xxx' => 'xxx@xxx.com' } s.source = { :git => 'https://github.com/xxx/TestLib.git', :tag => s.version.to_s } # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>' # iOS版本 s.ios.deployment_target = '8.0' # 源码所在路径 s.source_files = 'TestLib/Classes/**/*' # 资源文件所在地址 # s.resource_bundles = { # 'TestLib' => ['TestLib/Assets/*.png'] # } # 对外公开的h文件地址,swift一般用不到 # s.public_header_files = 'Pod/Classes/**/*.h' # 包含的系统framework # s.frameworks = 'UIKit', 'MapKit' # 包含的第三方pod # s.dependency 'AFNetworking', '~> 2.3' end更详细的介绍可以访问官网https://guides.cocoapods.org/syntax/podspec.html
配置好以后我们需要做一次验证,在工程目录下使用命令
pod lib lint 初次验证可能遇到的几个问题: