CocoaPods 在日常開發(fā)中的一些使用

最近工作中有用到所以就順便梳理一下知識(shí)點(diǎn)。參考鏈接

  • 1.指定源

CocoaPods支持Spec倉庫,可以建立自己的source,也可以使用非官方的源,只要是符合規(guī)定的都可以自定使用。
私有庫創(chuàng)建

source 'https://github.com/624990742/SwiftBase/Specs.git'//自己私有的
source 'https://github.com/CocoaPods/Specs.git'//官方
  • 2.隱藏警告

inhibit_warnings參數(shù)能夠有效的隱藏引入的pods第三方庫產(chǎn)生的warning警告。

(1).不顯示任何pod庫的警告可以在項(xiàng)目中Podfile文件中加入inhibit_all_warnings!。
platform :ios, '11.0'
inhibit_all_warnings!  # pod 的工程不顯示任何警告
(2).針對(duì)指定的庫隱藏警告
pod 'SnapKit', '~> 2.4', :inhibit_warnings => true
  • 3.使用git的HEAD指向的分支

pod 'SwiftBase', :head
  • 4.使用git指定使用 master 分支

pod 'Masonry', :git => 'https://github.com/SnapKit/Masonry.git'
  • 5.使用git指定branch

pod 'Reachability', :git => 'https://github.com/ashfurrow/Reachability.git', :branch => 'frameworks'
  • 6.使用git指定tag

pod 'Masonry', :git => 'https://github.com/SnapKit/Masonry.git', :tag => '1.1.0'
  • 7.使用git指定commit

pod 'ARTiledImageView', :git => 'https://github.com/dblockARTiledImageView', :commit => '1a31b864d1d56b1aaed0816c10bb55cf2e078bb8'
  • 8.使用第三方庫的子庫

(1).指定一個(gè)
pod 'QueryKit/Attribute'
(2).指定多個(gè)子庫
pod 'PolyvCloudClassSDK',:subspecs => ['Core','Player']
  • 9.使用本地代碼

:path可以指定本地代碼,不過需要確保目錄包含podspec文件。

 pod 'Masonry', :path => '~/Documents/Masonry'
  • 10.指定target的依賴庫

target :MyApp do  
  pod 'Masonry'
end
  • 11.排除taget

target 'MyApp Tests', :exclusive => true do  
  pod 'FBSnapshotTestCase', '1.4'
end
  • 12.排除taget

target 'YOUR_APP_NAME_HERE_Tests', :exclusive => true do
  pod 'Nimble-Snapshots'
end
  • 13.指定xcodeproj

默認(rèn)會(huì)使用Podfile文件同級(jí)目錄下第一個(gè) xcodeproj,但也可以指定。

xcodeproj 'MyProject'
target :test do  
  # This Pods library links with a target in another project.
  xcodeproj 'TestProject'
end
  • 14.指定連接的target

使用link_with可以指定連接一個(gè)或者多個(gè)target,不顯式指定的話,pods默認(rèn)會(huì)鏈接project的第一個(gè)target。

link_with 'MyFistApp', 'OtherOneApp'
  • 15.指定依賴庫的配置文件

pod 'PonyDebugger', :configuration => ['Release']
  • 16.指定target的配置文件

xcodeproj 'TestProject', 'Mac App Store' => :release, 'Test' => :debug
  • 17.使用Dynamic Frameworks代替Static Libraries

通過標(biāo)志use_frameworks!就可知開啟這個(gè)功能。如果需要使用Swift的庫,就必須加上這個(gè)標(biāo)志了。
  • 18.引入第三方庫的時(shí)候通常會(huì)有指定庫版本的操作,就比如pod 'Masonry', '~> 1.1.0'對(duì)應(yīng)的操作符解釋如下:

  pod 'Masonry','> 1.1.0' 大于1.1.0的版本,不包括1.1.0版本
  pod 'Masonry','>= 1.1.0' 大于等于1.1.0的版本
  pod 'Masonry','< 1.1.0'小于1.1.0的版本,不包括1.1.0版本
  pod 'Masonry','<= 1.1.0' 小于等于1.1.0的版本
  pod 'Masonry','~> 1.1.0' 相當(dāng)于'>= 1.1.0 且 ‘< 1.2.0’
  pod 'Masonry','~> 1.1' 相當(dāng)于'>= 1.1 且 ‘< 2.0’
  pod 'Masonry','~> 0' 相當(dāng)于不寫,即最新版本
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容