Podfile

作者: Natus_Vincere | 来源:发表于2018-03-13 17:38 被阅读0次

什么是 Podfile

Podfile是一个规范,用于描述一个或多个Xcode项目的目标依赖关系。 该文件应该简单地命名为Podfile。 指南中的所有示例均基于CocoaPods 1.0及更高版本。

  • Podfile 可以非常简单,这将 Alamofire 添加到单个目标中:
target 'MyApp' do
  use_frameworks!
  pod 'Alamofire', '~> 3.0'
end
  • 一个更复杂的 Podfile 链接应用程序及其测试包的示例:
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/Artsy/Specs.git'

platform :ios, '9.0'
inhibit_all_warnings!

target 'MyApp' do
  pod 'GoogleAnalytics', '~> 3.1'

  # Has its own copy of OCMock
  # and has access to GoogleAnalytics via the app
  # that hosts the test target

  target 'MyAppTests' do
    inherit! :search_paths
    pod 'OCMock', '~> 2.0.1'
  end
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    puts target.name
  end
end
  • 如果您希望多个目标 (targets) 共享相同的 pods,请使用abstract_target。
# There are no targets called "Shows" in any Xcode projects
abstract_target 'Shows' do
  pod 'ShowsKit'
  pod 'Fabric'

  # Has its own copy of ShowsKit + ShowWebAuth
  target 'ShowsiOS' do
    pod 'ShowWebAuth'
  end

  # Has its own copy of ShowsKit + ShowTVAuth
  target 'ShowsTV' do
    pod 'ShowTVAuth'
  end
end
  • 在 Podfile 的根部有隐含的抽象目标,所以你可以将上面的例子写成:
pod 'ShowsKit'
pod 'Fabric'

# Has its own copy of ShowsKit + ShowWebAuth
target 'ShowsiOS' do
  pod 'ShowWebAuth'
end

# Has its own copy of ShowsKit + ShowTVAuth
target 'ShowsTV' do
  pod 'ShowTVAuth'
end

指定 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和更高版本,基本上与没有它相同。

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

使用本地文件夹中的文件

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

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

使用此选项,CocoaPods 将假定给定的文件夹是 Pod 的根目录,并将直接从 Pods 项目中的文件链接文件。 这意味着您的编辑将在 CocoaPods installations 持续存在。 引用的文件夹可以是您最喜欢的软件配置管理方式查看,甚至可以是当前 repo 的 git 子模块。(The referenced folder can be a checkout of your favourite SCM or even a git submodule of the current repo.)

请注意,Pod 文件的 podspec 应该位于指定的文件夹中。

From a podspec in the root of a library repo.

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

  • 使用 master branch 的 repo:
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git'
  • 使用不同分支的 repo:
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'dev'
  • 使用 tag 的 repo :
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :tag => '3.1.1'
  • 或者指定一个 commit :
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :commit => '0f506b1c45'

但是,需要注意的是,这意味着该版本将不得不满足其他Pod的其他依赖项。

预计podspec文件位于repo的根目录中,如果此库的repo中没有podspec文件,则必须使用下面各节中概述的方法之一。

外部资源

相关文章

  • pod命令行操作

    首先:cd 项目touch Podfile一个文件vim Podfile进入Podfile文件在Podfile文件...

  • (四)Podfile vs. Podfile.lock

    下面是 Podfile 与 Podfile.lock 两个文件的对比: Podfile: Podfile.lock:

  • cocoapods 使用

    1 cd 空格 路径 2 touch Podfile 编辑 Podfile文件 1)输入 vim Podfile,...

  • CocoaPods的Podfile文件编写

    一、Podfile文件? 二、Podfile语法参考 Podfile Syntax Reference官网 1)永...

  • git 代码合并冲突

    Auto-merging Podfile.lock podfile.lock合并冲突 podfile.lock 该...

  • Flutter 项目升级报错处理

    1、flutter Warning: Podfile is out of dateWarning: Podfile...

  • Pod 新建项目

    1,打开命令行 cd 你的项目目录 2,新建Podfile touch Podfile 3, 编辑Podfile ...

  • cocoapods-prefer解析

    hook cocoapods的类 podfile 在podfile.rb文件实现在podfile调用的函数,传递参...

  • Podfile 库版本运算符

    一个简单的podfile: 一个更简单的podfile: 一个更更简单的podfile: 一个复杂的podfile...

  • Podfile

    什么是 Podfile Podfile是一个规范,用于描述一个或多个Xcode项目的目标依赖关系。 该文件应该简单...

网友评论

      本文标题:Podfile

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