轉(zhuǎn)自此文覺得整理的很清楚梯轻,還有一篇官方譯文
一個簡單的Podfile
target 'MyApp'
pod 'AFNetworking', '~> 1.0'
一個復(fù)雜的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í)行時的一些設(shè)置。
示例:
install! 'cocoapods',
:deterministic_uuids => false,
:integrate_targets => false
支持關(guān)鍵字:
: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’ 相當(dāng)于'>= 0.1.2 且 ‘< 0.2.0’
- ‘~> 0.1’ 相當(dāng)于'>= 0.1 且 ‘< 1.0’
- ‘~> 0’ 相當(dāng)于不寫闪水,即最新版本
編譯配置
// 在Release和App Store模式引用該庫
pod 'PonyDebugger', :configurations => ['Release', 'App Store']
// 在Release模式引用該庫
pod 'PonyDebugger', :configuration => ['Release']
Subspecs
在使用開源庫時报破,只是用該庫的一部分,可是使用如下寫法爆办。前提是當(dāng)前庫是支持Subspecs的难咕。
// 只引用QueryKit的Attribute子庫,不包含其它子庫
pod 'QueryKit/Attribute'
// 只引用QueryKit的Attribute和QuerySet子庫,不包含其它子庫
pod 'QueryKit', :subspecs => ['Attribute', 'QuerySet']
使用本地路徑下的文件
pod 'AFNetworking', :path => '~/Documents/AFNetworking'
使用已通過認(rèn)證的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)的關(guān)系余佃。每個target應(yīng)該對應(yīng)一個Xcode target暮刃。默認(rèn)情況下,子target的依賴關(guān)系是包含父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應(yīng)用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!
表示當(dāng)前target是抽象的,不會與真正的Xcode target掛鉤坏瘩。
inherit!
設(shè)置當(dāng)前target的繼承模式盅抚。
// Inheriting only search paths
target 'App' do
target 'AppTests' do
inherit! :search_paths
end
end
Target configuration
這些設(shè)置是控制被生成project的CocoaPods。包括指定編譯platform倔矾、指定鏈接的xcodeproj妄均。
platform
如果不指定,CocosPods將是默認(rèn)值哪自,當(dāng)前默認(rèn)值是:
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
指定當(dāng)前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
有戶自定義編譯設(shè)置
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允許用戶在被寫入硬盤享言、或者任何你想做的其它任務(wù)之前峻凫,對生成的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