CocoaPods中Podfile語法

轉(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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末览露,一起剝皮案震驚了整個濱河市荧琼,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖命锄,帶你破解...
    沈念sama閱讀 222,378評論 6 516
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件堰乔,死亡現(xiàn)場離奇詭異,居然都是意外死亡脐恩,警方通過查閱死者的電腦和手機镐侯,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,970評論 3 399
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來驶冒,“玉大人苟翻,你說我怎么就攤上這事∑郏” “怎么了崇猫?”我有些...
    開封第一講書人閱讀 168,983評論 0 362
  • 文/不壞的土叔 我叫張陵,是天一觀的道長需忿。 經(jīng)常有香客問我诅炉,道長,這世上最難降的妖魔是什么贴谎? 我笑而不...
    開封第一講書人閱讀 59,938評論 1 299
  • 正文 為了忘掉前任汞扎,我火速辦了婚禮,結(jié)果婚禮上擅这,老公的妹妹穿的比我還像新娘澈魄。我一直安慰自己,他們只是感情好仲翎,可當(dāng)我...
    茶點故事閱讀 68,955評論 6 398
  • 文/花漫 我一把揭開白布痹扇。 她就那樣靜靜地躺著,像睡著了一般溯香。 火紅的嫁衣襯著肌膚如雪鲫构。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,549評論 1 312
  • 那天玫坛,我揣著相機與錄音结笨,去河邊找鬼。 笑死湿镀,一個胖子當(dāng)著我的面吹牛炕吸,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播勉痴,決...
    沈念sama閱讀 41,063評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼赫模,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了蒸矛?” 一聲冷哼從身側(cè)響起瀑罗,我...
    開封第一講書人閱讀 39,991評論 0 277
  • 序言:老撾萬榮一對情侶失蹤胸嘴,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后斩祭,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體劣像,經(jīng)...
    沈念sama閱讀 46,522評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,604評論 3 342
  • 正文 我和宋清朗相戀三年停忿,在試婚紗的時候發(fā)現(xiàn)自己被綠了驾讲。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,742評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡席赂,死狀恐怖吮铭,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情颅停,我是刑警寧澤谓晌,帶...
    沈念sama閱讀 36,413評論 5 351
  • 正文 年R本政府宣布,位于F島的核電站癞揉,受9級特大地震影響纸肉,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜喊熟,卻給世界環(huán)境...
    茶點故事閱讀 42,094評論 3 335
  • 文/蒙蒙 一柏肪、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧芥牌,春花似錦烦味、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,572評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至弃理,卻和暖如春溃论,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背痘昌。 一陣腳步聲響...
    開封第一講書人閱讀 33,671評論 1 274
  • 我被黑心中介騙來泰國打工钥勋, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人辆苔。 一個月前我還...
    沈念sama閱讀 49,159評論 3 378
  • 正文 我出身青樓笔诵,卻偏偏與公主長得像,于是被迫代替她去往敵國和親姑子。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,747評論 2 361