介绍一些CocoaPods一些特别的用法html
系统版本:macOS Sierra 10.12.6github
Xcode: v9.2(9C40b)xcode
target 'MyApp' do pod 'AFNetworking','3.2.0' end
这是将AFNetworking
彻底限定在 3.2.0版本,不会更新ide
target 'MyApp' do pod 'AFNetworking','~> 3.2.0' end
这样设置 AFNetworking
会在 3.2.0 ~ 3.9.9 之间版本浮动,不包含4.0.0(这里就是泛指,没必要较真,不要提AFNetworking 没有3.9.9)ui
target 'MyApp' do pod 'AFNetworking', end
这样设置 AFNetworking
不限制版本,任何版本均可以,不过下载的版本下来确定是最新的。debug
提示code
在项目中,我建议使用方法一,也就是固定版本。特别是在多人开发的项目中orm
在项目中,可能会遇到更新pod。若是不指定版本的花,就会出现每一个人第三方库版本不同
若是是须要更新第三方库,直接修改版本号,更新pod便可。
尽可能小组内作到协调统一
'> 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和以上,等于没有此约束
source 'https://github.com/CocoaPods/Specs.git' source 'https://github.com/Artsy/Specs.git'
target 'MyApp' do pod 'AFNetworking',:head end
target 'MyApp' do pod 'LBXScan',git:'https://github.com/MxABC/LBXScan.git' end
target 'MyApp' do pod 'Reachability', :git => 'https://github.com/ashfurrow/Reachability.git', :branch => 'frameworks' end
target 'MyApp' do pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :tag => '3.2.0' end
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 'MyApp' do pod 'SDWebImage', '4.0' target 'otherTaget' do use_frameworks! pod 'AFNetworking','3.2.0' end end
target 'MyApp' :exclusive => true do pod 'AFNetworking','3.2.0' end
默认会使用
podfile
文件同级目录下第一个xcodeproj
,但也是能够指定的
xcodeproj 'testProject' target:test do pod 'AFNetworking','3.2.0' xcodeproj 'otherProject' end
若是不显式指定链接的target,Pods会默认链接project的第一个target。若是须要,可使用link_with指定链接一个活多个target
target link_with 'MyApp','otherApp' do pod 'AFNetworking','3.2.0' end
pod 'PonyDebugger', :configuration => ['Release']
xcodeproj 'TestProject', 'Mac App Store' => :release, 'Test' => :debug
经过标志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