美文网首页关于app安全性很常
CocoaPods 在日常开发中的一些使用

CocoaPods 在日常开发中的一些使用

作者: 90后的晨仔 | 来源:发表于2021-03-27 22:15 被阅读0次

    最近工作中有用到所以就顺便梳理一下知识点。参考链接

    • 1.指定源

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

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

    inhibit_warnings参数能够有效的隐藏引入的pods第三方库产生的warning警告

    (1).不显示任何pod库的警告可以在项目中Podfile文件中加入inhibit_all_warnings!
    platform :ios, '11.0'
    inhibit_all_warnings!  # pod 的工程不显示任何警告
    
    (2).针对指定的库隐藏警告
    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).指定一个
    pod 'QueryKit/Attribute'
    
    (2).指定多个子库
    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

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

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

    使用link_with可以指定连接一个或者多个target,不显式指定的话,pods默认会链接project的第一个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

    通过标志use_frameworks!就可知开启这个功能。如果需要使用Swift的库,就必须加上这个标志了。
    
    • 18.引入第三方库的时候通常会有指定库版本的操作,就比如pod 'Masonry', '~> 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'小于1.1.0的版本,不包括1.1.0版本
      pod 'Masonry','<= 1.1.0' 小于等于1.1.0的版本
      pod 'Masonry','~> 1.1.0' 相当于'>= 1.1.0 且 ‘< 1.2.0’
      pod 'Masonry','~> 1.1' 相当于'>= 1.1 且 ‘< 2.0’
      pod 'Masonry','~> 0' 相当于不写,即最新版本
    

    相关文章

      网友评论

        本文标题:CocoaPods 在日常开发中的一些使用

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