陈斌彬的技术博客

Stay foolish,stay hungry

CocoaPods 的一些使用

指定源

CocoaPods支持私有 Spec 仓库的,我们可以建立自己的源,也可以使用非官方的源,只要是符合规定的都可以指定。

source 'https://github.com/artsy/Specs.git'  
source 'https://github.com/CocoaPods/Specs.git'

抑制警告

inhibit_warnings参数能够有效的抑制CocoaPods引入的第三方代码库产生的warning。

可以全部指定。

inhibit_all_warnings!

也可以针对指定。

pod 'ReactiveCocoa', '~> 2.4', :inhibit_warnings => true

使用git的HEAD指向的分支

pod 'ISO8601DateFormatter', :head

使用 master 分支

pod 'ARAnalytics/Mixpanel', :git => 'https://github.com/orta/ARAnalytics.git'

指定branch

pod 'Reachability', :git => 'https://github.com/ashfurrow/Reachability.git', :branch => 'frameworks'

指定tag

pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :tag => '0.7.0'

指定commit

pod 'ARTiledImageView', :git => 'https://github.com/dblockARTiledImageView', :commit => '1a31b864d1d56b1aaed0816c10bb55cf2e078bb8'

使用子库

可以这样

pod 'QueryKit/Attribute'

也可以这样指定多个子库

pod 'QueryKit', :subspecs => ['Attribute', 'QuerySet']

使用本地代码

通过:path可以指定本地代码,不过需要确保目录包含podspec文件。

pod 'AFNetworking', :path => '~/Documents/AFNetworking'

指定target的依赖库

target :ZipApp do  
  pod 'SSZipArchive'
end

排除taget

target 'Artsy Tests', :exclusive => true do  
  pod 'FBSnapshotTestCase', '1.4'
end

指定xcodeproj

默认会使用Podfile文件同级目录下第一个xcodeproj,但也可以指定

xcodeproj 'MyProject'
target :test do  
  # This Pods library links with a target in another project.
  xcodeproj 'TestProject'
end

指定连接的target

如果不显式指定连接的target,Pods会默认连接project的第一个target。如果需要,可以使用link_with指定连接一个或多个target

link_with 'MyApp', 'MyOtherApp'

指定依赖库的配置文件

pod 'PonyDebugger', :configuration => ['Release']

指定target的配置文件

xcodeproj 'TestProject', 'Mac App Store' => :release, 'Test' => :debug

使用Dynamic Frameworks代替Static Libraries

通过标志use_frameworks!就可知开启这个功能。如果需要使用Swift的库,就必须加上这个标志了。

加快pod install/update 速度

使用CocoaPods来添加第三方类库,无论是执行pod install还是pod updat很多时候都卡在了Analyzing dependencies不动,这是更新本地的pod spec所以文件导致的。通过–no-repo-update标志可以不更新本地pod spec索引。当然首次install不应该添加这个标志,后续修改Podfile的时候可以适当使用,加快pod速度。

pod install --no-repo-update  
pod update --no-repo-update

输出详细日志

pod update --verbose