zoukankan      html  css  js  c++  java
  • [CocoaPods]Podfile文件

    Podfile是一个描述一个或多个Xcode项目的目标依赖项的规范。该文件应该只是命名Podfile。指南中的所有示例都基于CocoaPods 1.0及更高版本。

    Podfile可以非常简单,这会将Alamofire添加到单个目标:

    1 target 'MyApp' do
    2   use_frameworks!
    3   pod 'Alamofire', '~> 3.0'
    4 end

    链接应用程序及其测试包的更复杂Podfile的示例:

     1 source 'https://github.com/CocoaPods/Specs.git'
     2 source 'https://github.com/Artsy/Specs.git'
     3 
     4 platform :ios, '9.0'
     5 inhibit_all_warnings!
     6 
     7 target 'MyApp' do
     8   pod 'GoogleAnalytics', '~> 3.1'
     9 
    10   # Has its own copy of OCMock
    11   # and has access to GoogleAnalytics via the app
    12   # that hosts the test target
    13 
    14   target 'MyAppTests' do
    15     inherit! :search_paths
    16     pod 'OCMock', '~> 2.0.1'
    17   end
    18 end
    19 
    20 post_install do |installer|
    21   installer.pods_project.targets.each do |target|
    22     puts target.name
    23   end
    24 end

    如果您希望多个目标共享相同的pod,请使用abstract_target

     1 # There are no targets called "Shows" in any Xcode projects
     2 abstract_target 'Shows' do
     3   pod 'ShowsKit'
     4   pod 'Fabric'
     5 
     6   # Has its own copy of ShowsKit + ShowWebAuth
     7   target 'ShowsiOS' do
     8     pod 'ShowWebAuth'
     9   end
    10 
    11   # Has its own copy of ShowsKit + ShowTVAuth
    12   target 'ShowsTV' do
    13     pod 'ShowTVAuth'
    14   end
    15 end

    Podfile的根目录中有隐式抽象目标,因此您可以将上面的示例写为:

     1 pod 'ShowsKit'
     2 pod 'Fabric'
     3 
     4 # Has its own copy of ShowsKit + ShowWebAuth
     5 target 'ShowsiOS' do
     6   pod 'ShowWebAuth'
     7 end
     8 
     9 # Has its own copy of ShowsKit + ShowTVAuth
    10 target 'ShowsTV' do
    11   pod 'ShowTVAuth'
    12 end

    从0.x迁移到1.0

    我们有一篇博客文章解释了深度的变化。

    指定pod版本

    从项目开始时,您可能希望使用最新版本的Pod。如果是这种情况,只需省略版本要求即可。

    pod 'SSZipArchive'

    稍后在项目中,您可能希望冻结到Pod的特定版本,在这种情况下,您可以指定该版本号。

    pod 'Objection', '0.9'

    除了没有版本或特定的版本,也可以使用逻辑运算符:

    • '> 0.1' 任何高于0.1的版本
    • '>= 0.1' 版本0.1和任何更高版本
    • '< 0.1' 任何低于0.1的版本
    • '<= 0.1' 版本0.1和任何较低版本

    除了逻辑运算符,CocoaPods还有一个乐观的运算符~>

    • '~> 0.1.2' 版本0.1.2和版本高达0.2,不包括0.2和更高
    • '~> 0.1' 版本0.1和版本高达1.0,不包括1.0和更高版本
    • '~> 0' 版本0及更高版本,这与没有版本基本相同。

    有关版本控制策略的更多信息,请参阅:

    • 语义版本控制
    • RubyGems版本控制策略
    • 谷歌有一个关于它是如何工作的精彩视频:“CocoaPods和Squiggly Arrow的案例(Route 85)”。

    使用本机文件夹中的文件。

    如果您想与其客户端项目一起开发Pod,您可以使用:path

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

    使用此选项,CocoaPods将假定给定的文件夹是Pod的根目录,并将直接从Pods项目中的文件链接。这意味着您的编辑将在CocoaPods安装之间保留。引用的文件夹可以是您最喜欢的SCM的结帐,甚至是当前仓库的git子模块。

    请注意,podspecPod文件的位于预期的指定文件夹中。

    来自库仓库根目录中的podspec。

    有时您可能想要使用Pod的最新版本,特定版本或您自己的分支。如果是这种情况,您可以使用pod声明指定。

    要使用master回购的分支:

    pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git'

    要使用repo的不同分支:

    pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'dev'

    要使用repo的标记:

    pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :tag => '3.1.1'

    或指定提交:

    pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :commit => '0f506b1c45'

    但值得注意的是,这意味着该版本必须满足其他Pod对Pod的任何其他依赖关系。

    podspec文件应该位于repo的根目录中,如果此库podspec尚未在其repo中有文件,则必须使用以下部分中列出的方法之一。

  • 相关阅读:
    条件判断
    字符串和编码
    排序算法 C++实现
    Ubuntu16.04下 pip的安装与使用
    剑指offer(19): 顺时针打印矩阵
    剑指offer(21):栈的压入、弹出序列
    派生类对象地址赋给基类指针后, 指针对基类和派生类的函数调用
    synergy: error while loading shared libraries: libdns_sd.so.1: cannot open shared object file
    OpenCV Error: Assertion failed + error: (-215) 使用ros opencv中的DNN模块报错
    《 MySQL必知必会 》下载 以及 Ubuntu16.04 下配置其使用的软件环境
  • 原文地址:https://www.cnblogs.com/strengthen/p/10638884.html
Copyright © 2011-2022 走看看