在项目开发过程当中咱们不可避免的使用到第三方开发库,这篇文章主要讲解了一款类库管理工具CocoaPods,下面就为你们分析一下CocoaPods的一种文件格式语法Podspec。html
Podspec规范的描述了一个pod库的版本,它包括有关应从何处获取源、要使用什么文件、应用的构建设置以及其余通常元数据(如其名称、版本和描述)的详细信息。ios
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.c++
在iOS项目下运行pod init
会生成以下文件,相信iOS开发的童鞋对他很是熟悉了,就不在过多的介绍git
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
# 添加网络库
pod 'AFNetworking', '~> 3.2.1'
target 'Demo' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
# Pods for Demo
end
复制代码
小技巧:若是想要搜索某个库,可使用pod search
,例如:pod search AFNetworking
github
pod spec createsql
pod spec create [
NAME
|https://github.com/USER/REPO
]bash
在当前工做目录中建立一个名为PodSpec的PodSpec NAME.podspec。若是传递了GitHub网址,则预先填充规范。
网络
Pod的名称,定义该库的名称,例如:app
s.name = 'AFNetworking' 等等框架
libraries,用户目标(应用程序)须要连接的系统库列表,注意是须要链接的系统库列表, 例如在库中引入了其余库文件,可是其余库文件又须要某些系统的库,这时咱们就须要这种方式引入(这个地方在开发Flutter iOS库文件时坑了我整整快一天了各类第三方库引用,而后又各类问题)
s.libraries = 'xml2', 'z', 'sqlite3', 'c++'
frameworks,用户目标须要连接的系统框架列表,注意是须要连接的系统框架列表
s.frameworks = 'QuartzCore', 'CoreData', 'MobileCoreServices', 'CFNetwork', 'CoreGraphics'
dependency, 对其余Pod或“子规范”的依赖性。依赖关系能够指定版本要求。~>建议使用乐观版本指示器,由于它能够很好地控制版本,而不会过于严格。例如, ~> 1.0.1至关于>= 1.0.1结合使用< 1.1。一样, ~> 1.0将匹配1.0,1.0.1,1.1,但不会升级到2.0。
s.dependency 'MBProgressHUD', '~> 0.5'
vendored_frameworks, 随Pod一块儿提供的框架捆绑包的路径
s.vendored_frameworks = 'A.framework', 'B.framework'
上述三、不经常使用
的就是就是今天遇到的坑
更多其余功能请详见
:guides.cocoapods.org/syntax/pods…