CocoaPods 略为高级使用

CocoaPods功能不算太强大,但大部分时候足够好用,仅仅是最基本的样例配置,就可以满足你项目的大部分需求,但了解更多的一一些的特性,会让你更得心应手。

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

source https://github.com/[gitbub name]/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/[github name]/xxx.git'

指定branch

pod 'Reachability', :git => 'https://github.com/[github name]/xxx.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'
#或
pod 'AFNetworking', :podspec => 'AFNetworking.podspec'

指定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

当然可以结合

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

XCode的Cocoapods插件####

cocoapods-xcode-plugin是一个XCode的插件,让你方便操作Cocoapods,那是相当好用的一个插件。

XCode的Cocoapods插件.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 项目组件化、平台化是技术公司的共同目标,越来越多的技术公司推崇使用pod管理第三方库以及私有组件,一方面使项目架构...
    swu_luo阅读 22,672评论 0 39
  • 一. CocoaPods的介绍 什么是CocoaPods?CocoaPods是一个负责管理iOS项目中第三方开源库...
    辉712阅读 9,404评论 0 7
  • 一、iOS和OSX中添加第三方依赖库1.1 CocoaPods介绍1.2 Carthage介绍1.3 CocoaP...
    小米锅巴阅读 6,641评论 0 8
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,590评论 19 139
  • CocoaPods操作手册 本文档介绍了啥? 为什么要使用CocoaPods? 如何安装CocoaPods? Po...
    风小钻阅读 12,240评论 1 10