一个简单的Podfile
target 'MyApp'
pod 'AFNetworking', '~> 1.0'
一个复杂的Podfile
platform :ios, '9.0'
inhibit_all_warnings!
target "MyApp" do
pod 'ObjectiveSugar', '~> 0.5'
target "MyAppTests" do
inherit! :search_paths
pod 'OCMock', '~> 2.0.1'
end
end
post_install do |installer|
installer.pods_project.targets.each do |target|
puts "#{target.name}"
end
end
Root Options
install!
pod install执行时的一些设置。
示例:
install! 'cocoapods',
:deterministic_uuids => false,
:integrate_targets => false
支持关键字:
:clean
:deduplicate_targets
:deterministic_uuids
:integrate_targets
:lock_pod_sources
Dependencies
pod
// 使用最新版本
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.2’ 相当于'>= 0.1.2 且 ‘< 0.2.0’
‘~> 0.1’ 相当于'>= 0.1 且 ‘< 1.0’
‘~> 0’ 相当于不写,即最新版本
编译配置
// 在Release和App Store模式引用该库
pod 'PonyDebugger', :configurations => ['Release', 'App Store']
// 在Release模式引用该库
pod 'PonyDebugger', :configuration => ['Release']
Subspecs
在使用开源库时,只是用该库的一部分,可是使用如下写法。前提是当前库是支持Subspecs的。
// 只引用QueryKit的Attribute子库,不包含其它子库
pod 'QueryKit/Attribute'
// 只引用QueryKit的Attribute和QuerySet子库,不包含其它子库
pod 'QueryKit', :subspecs => ['Attribute', 'QuerySet']
使用本地路径下的文件
pod 'AFNetworking', :path => '~/Documents/AFNetworking'
使用已通过认证的repo
// 使用master分支
pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git'
// 使用指定分支
pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :branch => 'dev'
// 使用指定tag
pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :tag => '0.7.0'
// 使用某一次提交
pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :commit => '082f8319af'
指定podspec文件
pod 'JSONKit', :podspec => 'https://example.com/JSONKit.podspec'
podspec
我也不太明白
podspec
podspec :name => 'QuickDialog'
podspec :path => '/Documents/PrettyKit/PrettyKit.podspec'
target
定义一个依赖库与target(Xcode project)的关系。每个target应该对应一个Xcode target。默认情况下,子target的依赖关系是包含父target的,除非指定非继承父target。
定义一个target
target "ZipApp" do
pod 'SSZipArchive'
end
在父target中定义SSZipArchive pod,仅支持父target
target "ZipApp" do
pod 'SSZipArchive'
target "ZipAppTests" do
inherit! :search_paths
pod 'Nimble'
end
end
通过在父target中定义target应用Pods支持多个targets
target "ShowsApp" do
pod 'ShowsKit'
Has it's own copy of ShowsKit + ShowTVAuth
target "ShowsTV" do
pod "ShowTVAuth"
end
Has it's own copy of Specta + Expecta
and has access to ShowsKit via the app
that the test target is bundled into
target "ShowsTests" do
inherit! :search_paths
pod 'Specta'
pod 'Expecta'
end
end
abstract_target
定义一个abstract_target,方便被所有继承target使用。
定义abstract_target
abstract_target 'Networking' do
pod 'AlamoFire'
target 'Networking App 1'
target 'Networking App 2'
end
定义一个abstract_target包含多个targets
There are no targets called "Shows" in any Xcode projects
abstract_target "Shows" do
pod 'ShowsKit'
Has it's own copy of ShowsKit + ShowWebAuth
target "ShowsiOS" do
pod "ShowWebAuth"
end
Has it's own copy of ShowsKit + ShowTVAuth
target "ShowsTV" do
pod "ShowTVAuth"
end
Has it's own copy of Specta + Expecta
and has access to ShowsKit via the app
that the test target is bundled into
target "ShowsTests" do
inherit! :search_paths
pod 'Specta'
pod 'Expecta'
end
end
abstract!
表示当前target是抽象的,不会与真正的Xcode target挂钩。
inherit!
设置当前target的继承模式。
// Inheriting only search paths
target 'App' do
target 'AppTests' do
inherit! :search_paths
end
end
Target configuration
这些设置是控制被生成project的CocoaPods。包括指定编译platform、指定链接的xcodeproj。
platform
如果不指定,CocosPods将是默认值,当前默认值是:
4.3 for iOS, 10.6 for OS X, 9.0 for tvOS and 2.0 for watchOS.
如果对系统有要求(iOS < 4.3),armv6 框架将添加至ARCHS.
platform :ios, "4.0"
platform :ios
project
指定当前target链接的project。若未指定,表示target链接与同路径(与podfile文件同路径)下target同名的project。
指定用户project
This Target can be found in a Xcode project called FastGPS
target "MyGPSApp" do
project 'FastGPS'
...
end
Same Podfile, multiple Xcodeprojects
target "MyNotesApp" do
project 'FastNotes'
...
end
有户自定义编译设置
project 'TestProject', 'Mac App Store' => :release, 'Test' => :debug
xcodeproj
TODO: This method can be deleted once people have migrated to this 1.0 DSL.
link_with
TODO: This method can be deleted once people have migrated to this 1.0 DSL.
inhibit_all_warnings!
抑制CocoaPods库的所有警告。该属性会被子target继承。
pod 'SSZipArchive', :inhibit_warnings => true
pod 'SSZipArchive', :inhibit_warnings => false
use_frameworks!
用frameworks 替代Pods静态库。该属性被子target继承。
Workspace
workspace
指定workspace。若未指定,表示是与podfile同路径下,且与target同名的workspace文件。例如:
workspace 'MyWorkspace'
generate_bridge_support!
Specifies that a BridgeSupport metadata document should be generated from the headers of all installed Pods.
This is for scripting languages such as MacRuby, Nu, and JSCocoa, which use it to bridge types, functions, etc.
set_arc_compatibility_flag!
已经被CocoaPods 1.0放弃。
Source
指定资源位置。
source 'https://github.com/artsy/Specs.git'
source 'https://github.com/CocoaPods/Specs.git'
Hooks
plugin
指定需要的插件。
plugin 'cocoapods-keys', :keyring => 'Eidolon'
plugin 'slather'
pre_install
Hook允许用户在Pods下载完成,但还未安装前对Pods做一些修改。
它接受 Pod::Installer 作为唯一的参数.
在Podfile定义pre-install hook
pre_install do |installer|
Do something fancy!
end
post_install
Hook允许用户在被写入硬盘、或者任何你想做的其它任务之前,对生成的Xcode project做最后的改变。
它接受 Pod::Installer 作为唯一的参数.
例如:
Customising the build settings of all targets
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['GCC_ENABLE_OBJC_GC'] = 'supported'
end
end
end
作者:Jabir_Zhang
链接:https://www.jianshu.com/p/900db3060f0f
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。