- 指明索引库
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/Artsy/Specs.git'
- 屏蔽所有来自于cocoapods依赖库的警告
inhibit_all_warnings!
- 你可以全局定义,也能在子target里面定义,也可以指定某一个库:
pod 'SSZipArchive', :inhibit_warnings => true
pod 'ShowTVAuth', :inhibit_warnings => false
- use_frameworks!
通过指定use_frameworks!要求生成的是framework而不是静态库。
如果使用use_frameworks!命令会在Pods工程下的Frameworks目录下生成依赖库的framework
如果不使用use_frameworks!命令会在Pods工程下的Products目录下生成.a的静态库
Dependencies
- 如果后面不写依赖库的具体版本号,那么cocoapods会默认选取最新版本。
pod 'SSZipArchive'
- 如果你想要特定的依赖库的版本,就需要在后面写上具体版本号,格式:
pod 'Objection', '0.9'
- 也可以指定版本范围
> 0.1 高于0.1版本(不包含0.1版本)的任意一个版本
>= 0.1 高于0.1版本(包含0.1版本)的任意一个版本
< 0.1 低于0.1版本(不包含0.1版本)的任意一个
<= 0.1低于0.1版本(包含0.1版本)的任意一个
~> 0.1.2 版本 0.1.2的版本到0.2 ,不包括0.2。这个基于你指定的版本号的最后一个部分。这个例子等效于>= 0.1.2并且 <0.2.0,并且始终是你指定范围内的最新版本。
Build configurations
- 默认情况下, 依赖项会被安装在所有target的build configuration中。为了调试或者处于其他原因,依赖项只能在给定的build configuration中被启用。
- 下面写法指明只有在Debug和Beta模式下才有启用配置
pod 'PonyDebugger', :configurations => ['Debug', 'Beta']
- 或者,可以弄白名单只指定一个build configurations。
pod 'PonyDebugger', :configuration => 'Debug'
Subspecs
- 仅安装QueryKit库下的Attribute模块
pod 'QueryKit/Attribute'
- 仅安装QueryKit下的Attribute和QuerySet模块
pod 'QueryKit', :subspecs => ['Attribute', 'QuerySet']
- 我们也可以指定依赖库的来源地址。如果我们想引入我们本地的一个库,可以这样写
pod 'AFNetworking', :path => '~/Documents/AFNetworking'
指定分支或节点
- 引入指定的分支
pod 'AFNetworking', :git => 'https://github.com/gowalla/ AFNetworking.git', :branch => 'dev'
- 引入某个节点的代码
pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :tag => '0.7.0'
- 引入某个特殊的提交节点
pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :commit => '082f8319af'
Target
- target应该与Xcode的target相符。默认情况下,target包含定义在块外的依赖,除非指定不使用inherit!来继承。
- abstract_target :定义一个抽象的target,为了方便target目标依赖继承。
# 指定当前target是抽象target。
target ‘A’ do
abstract!
end
- 设置当前target的继承关系
target 'App’ do
target ‘A’ do
#这个target 继承 父级所有行为
inherit! :complete
end
target ‘B’ do
#这个target 不继承 父级所有行为
inherit! :none
end
target ‘C’ do
#target 仅继承 父级的搜索路劲
inherit! :search_paths
end
end
def命令来声明一个pod集
def 'CustomPods’
pod 'IQKeyboardManagerSwift’
end
#然后,我们就可以在需要引入的target处引入
target 'MyTarget' do CustomPods
end