【iOS CocoaPods篇】iOS CocoaPods一些特別的用法 指定版本、版本介紹、忽略警告

簡介

介紹一些CocoaPods一些特別的用法html

CocoaPods github地址ios

CocoaPods 官方地址git

編譯環境

系統版本:macOS Sierra 10.12.6github

Xcode: v9.2(9C40b)xcode

1. 指定第三方庫版本

1. 固定版本
target 'MyApp' do
 pod 'AFNetworking','3.2.0'
end

這是將AFNetworking 徹底限定在 3.2.0版本,不會更新ide

2.小版本浮動
target 'MyApp' do
 pod 'AFNetworking','~> 3.2.0'
end

這樣設置 AFNetworking 會在 3.2.0 ~ 3.9.9 之間版本浮動,不包含4.0.0(這裏就是泛指,沒必要較真,不要提AFNetworking 沒有3.9.9)ui

3.徹底不限制版本
target 'MyApp' do
  pod 'AFNetworking',
end

這樣設置 AFNetworking 不限制版本,任何版本均可以,不過下載的版本下來確定是最新的。debug

提示code

在項目中,我建議使用方法一,也就是固定版本。特別是在多人開發的項目中orm

在項目中,可能會遇到更新pod。若是不指定版本的花,就會出現每一個人第三方庫版本不同

若是是須要更新第三方庫,直接修改版本號,更新pod便可。

儘可能小組內作到協調統一

4.官方解釋版本

1522107151301.jpg

'> 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.2
'~> 0.1'     0.1以上 1.0如下,不含0.1
'~> 0'       0和以上,等於沒有此約束

CocoaPods 支持私有Spec倉庫,咱們能夠創建本身的源,也可使用非官方的源,只要符合規定的均可以指定

source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/Artsy/Specs.git'
使用git的HEAD指向的分支
target 'MyApp' do
  pod 'AFNetworking',:head
end
使用master分支
target 'MyApp' do
  pod 'LBXScan',git:'https://github.com/MxABC/LBXScan.git'
end
指定branch
target 'MyApp' do
 pod 'Reachability', :git => 'https://github.com/ashfurrow/Reachability.git', :branch => 'frameworks'
end
指定tag
target 'MyApp' do
 pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :tag => '3.2.0'
end
指定commit
target 'MyApp' do
 pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :commit => 'e976d63'
end
使用子庫
target 'MyApp' do
 pod 'QueryKit/Attribute'
end
使用多個子庫
target 'MyApp' do
 pod 'QueryKit', :subspecs => ['Attribute', 'QuerySet']
end
使用本地庫

經過:path 能夠指定本地代碼,不過須要確保目錄中包含 podspec 文件。

target 'MyApp' do
 pod 'AFNetworking', :path => '~/Documents/AFNetworking'
end
指定target的依賴庫
target 'MyApp' do
 pod 'SDWebImage', '4.0'
    target 'otherTaget' do
     use_frameworks!
     pod 'AFNetworking','3.2.0'
    end
 
end
排除target
target 'MyApp' :exclusive => true do
  pod 'AFNetworking','3.2.0'
end
指定xocdeproj

默認會使用 podfile 文件同級目錄下第一個xcodeproj ,但也是能夠指定的

xcodeproj 'testProject'
 target:test do
   pod 'AFNetworking','3.2.0'
   xcodeproj 'otherProject'   
  end
指定鏈接的target

若是不顯式指定鏈接的target,Pods會默認鏈接project的第一個target。若是須要,可使用link_with指定鏈接一個活多個target

target link_with 'MyApp','otherApp' do
  pod 'AFNetworking','3.2.0'
 end
指定依賴庫的配置文件
pod 'PonyDebugger', :configuration => ['Release']
指定target的配置文件
xcodeproj 'TestProject', 'Mac App Store' => :release, 'Test' => :debug
使用Dynamic Frameworks代替Static Libraries

經過標誌use_frameworks!就可知開啓這個功能。若是須要使用Swift的庫,就必須加上這個標誌了。

抑制警告

inhibit_warnings參數可以有效的抑制CocoaPods引入的第三方代碼庫產生的warning

target 'MyApp' do
 pod 'AFNetworking','3.2.0',:inhibit_warnings => true 
end
全局抑制警告
platform :ios, '8.0'
 inhibit_all_warnings!
 target 'MyApp' do
  pod 'AFNetworking','3.2.0'
 end
相關文章
相關標籤/搜索