一個簡單的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執(zhí)行時的一些設置。
示例:
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.
如果對系統(tǒng)有要求(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靜態(tài)庫。該屬性被子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!
已經(jīng)被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 作為唯一的參數(shù).
在Podfile定義pre-install hook
pre_install do |installer|
# Do something fancy!
end
post_install
Hook允許用戶在被寫入硬盤宾娜、或者任何你想做的其它任務之前,對生成的Xcode project做最后的改變扇售。
它接受 Pod::Installer 作為唯一的參數(shù).
例如:
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
一個簡單的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執(zhí)行時的一些設置前塔。
示例:
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.
如果對系統(tǒng)有要求(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靜態(tài)庫。該屬性被子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!
已經(jīng)被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 作為唯一的參數(shù).
在Podfile定義pre-install hook
pre_install do |installer|
# Do something fancy!
end
post_install
Hook允許用戶在被寫入硬盤晴氨、或者任何你想做的其它任務之前康嘉,對生成的Xcode project做最后的改變。
它接受 Pod::Installer 作為唯一的參數(shù).
例如:
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