Podfile常用三方庫及其配置一:基礎配置與說明

關聯文章
Podfile常用三方庫及其配置一:基礎配置與說明
Podfile常用三方庫及其配置二:Pod常用框架
Podfile常用三方庫及其配置三:工具推薦

基礎:

忽略cocoapods中多個specs源引起的警告問題:

install! 'cocoapods', :warn_for_unused_master_specs_repo => false

推薦使用CDN trunk源:

source 'https://cdn.cocoapods.org/'

Podfile源配置

#添加源方式,任選一,推薦使用CDN trunk源
## 1. cdn trunk源:通過CDN實時獲取https://github.com/CocoaPods/Specs.git最新數據。
source 'https://cdn.cocoapods.org/'

## 2. Specs源:舊版CocoaPods不支持CDN,直接獲取https://github.com/CocoaPods/Specs.git最新數據。
source 'https://github.com/CocoaPods/Specs.git'

## 3. 清華大學鏡像源:注意有緩存,獲取的數據不是最新的,但是解決了國內網絡訪問問題。
source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'

Podfile 配置文件說明:

build configurations (編譯配置) 默認情況下,依賴項會被安裝在所有target的build configrations中:

 //為了調試或者其他原因,他們可以在給定的configurations中啟用
 pod 'PonyDebugger', :configurations => ['Debug', 'Beta']
 //或者,你可以至指定一個build configration
 pod 'PonyDebugger', :configuration => ‘Debug'

source: 默認被指定的依賴項會在全局級別的指定源中匹配搜索。可以為特依賴關系指定源

 //指定特定源中搜索,并忽略任何全局源*
 pod 'PonyDebugger', :source => 'https://github.com/CocoaPods/Specs.git'

Subspecs: 當使用依賴庫名字引入依賴庫時,也會默認安裝依賴庫中的所有子模塊。

 //指定引用指定子模塊
 pod 'QueryKit/Attribute’
 //指定一個子模塊集合
 pod 'QueryKit', :subspecs => ['Attribute', 'QuerySet']

依賴(Dependencies)

  1. pod: 指明項目依賴,一個依賴是由一個pod名稱和一個可選版本定義

a. 如果不添加版本號,pod默認使用最新的 如:pod ’SSZipArchive’
b. 如果項目需要一個指定的pod,需要添加版本號,如: pod ‘objection’, ‘0.9’
c. 指定版本范圍

. = 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<= pod < 0.2 版本 ,安裝這個范圍內最新的版本

  1. podspec : 引用倉庫根目錄的(from a pod spec in the root of a library repository)引用pod在指定節點或者分支
 主分支:
 pod 'AFNetworking', :git => 'https:github.com/gowalla/AFNetworking.git'

 指定分支: :branch => 'dev'
 pod 'AFNetworking', :git => 'https:github.com/a/AFNetworking.git', :branch => 'dev'

 指定的tag:  :tag => '0.7.0'
 pod 'AFNetworking', :git => 'https:github.com/b/AFNetworking.git', :tag => '0.7.0'

 指定的節點: :commit => '082f8319af'
 pod 'AFNetworking', :git => 'https:github.com/c/AFNetworking.git', :commit =>  ‘082f8319af'
  1. 添加本地框架
添加本地框架  path后面跟本地框架的詳細路徑
pod 'TKPermissionKit' , :path => ".. /"
  1. abstract_target :定義一個抽象的target,為了方便target目標依賴繼承。 這個target是沒有被定義在xcode中的。 例子:
  a.定義一個抽象target
 abstract_target 'Networking' do     
     pod ‘AlamoFire'
     target 'Networking App 1’
     target 'Networking App 2’
 end
  b. 定義一個包含多個target的抽象target
 # 注意:這是個抽象的target工程中并沒有這個target.引入ShowsKit 
 abstract_target 'Shows' do 
     pod 'ShowsKit’ 
     # ShowsiOS target會引入ShowWebAuth庫以及繼承自Shows的ShowsKit庫 
     target 'ShowsiOS' do 
         pod 'ShowWebAuth’ 
     end
     # ShowsTV target會引入ShowTVAuth庫以及繼承自Shows的ShowsKit庫 
     target 'ShowsTV’ do
         pod ‘ShowTVAuth'
     end 
     # ShowsTests target引入了Specta和Expecta庫,并且指明繼承Shows,所以也會引入ShowsKit
     target 'ShowsTests’ do
         inherit! :search_paths 
         pod 'Specta’ 
         pod 'Expecta’ 
     end 
 end
  1. script_phase 使用這個命令給target添加shell腳本
 target ‘A’ do
     script_phase :name => 'HelloWorldScript', :script => 'echo "Hello World”'
     script_phase :name => 'HelloWorldScript', :script => 'puts "Hello World"', :shell_path => '/usr/bin/ruby'
 end
  1. abstract! 指定當前target是抽象target
 target ‘A’ do
     abstract!
 end
  1. inherit! 設置當前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
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容