美文网首页iOS 的那些事儿
CocoaPods 略为高级使用

CocoaPods 略为高级使用

作者: O2Space_Xiu | 来源:发表于2016-11-22 19:57 被阅读645次

    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

    相关文章

      网友评论

        本文标题:CocoaPods 略为高级使用

        本文链接:https://www.haomeiwen.com/subject/aihmpttx.html