美文网首页
Podfile语法参考(译)

Podfile语法参考(译)

作者: KnowWhy | 来源:发表于2019-03-06 15:13 被阅读0次

Podfile

Podfile 是一个规范,描述了一个或多个 Xcode 工程中 targets 的依赖关系。

Podfile 可以非常简单:

target 'MyApp'
pod 'AFNetworking', '~> 1.0'

更复杂的 Podfile 示例可以是:

platform :ios, '9.0'
inhibit_all_warnings!

target 'MyApp' do
  pod 'ObjectiveSugar', '~> 0.5'

  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

Root Options

整体应用于 Podfile 的配置。

  • install! 声明安装期间要使用的安装方法和选项。

install!

指定 CocoaPods 安装此 Podfile 时要使用的安装方法和选项。

第一个参数表示要使用的安装方法;下一个参数表示安装选项。

目前唯一可接受的安装方法是 cocoapods ,所以你总是将这个值用作第一个参数;但是在将来的版本中可能会提供更多安装方法。

示例:

指定自定义 CocoaPods 安装选项

install! 'cocoapods',
         :deterministic_uuids => false,
         :integrate_targets => false

支持的keys:

以下选项默认值均为 true

:clean

:deduplicate_targets

:deterministic_uuids

:integrate_targets

:lock_pod_sources

:warn_for_multiple_pod_sources

以下选项默认值均为 false

:share_schemes_for_development_pods

:disable_input_output_paths

:preserve_pod_file_structure

Dependencies

Podfile 指定每个用户 target 的依赖关系。

  • pod 声明一个特定依赖项
  • podspec 提供一个简单的API来创建 podspecs
  • target 是您如何将依赖项定位到Xcode项目中的特定目标

pod

指定项目的依赖项。

一个依赖项通过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的任何版本
  • <= 0.1 低于或等于0.1的任何版本
  • ~> 0.1.2 高于或等于0.1.2且低于0.2之间的任何版本;此运算符基于您在版本要求中指定的最后一个组件工作。该示例等同于 >= 0.1.2并且 < 0.2.0 并且将始终匹配符合您要求的最新已知版本。

可以指定版本要求列表以进行更细粒度的控制。

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

Build configurations

默认情况下,依赖项安装在 target 的所有构建配置中。 有时出于调试目的或其他原因,仅只能在某个构建配置列表中启用它们。

pod 'PonyDebugger', :configurations => ['Debug', 'Beta']

或者,您可以指定将其包含在单个构建配置中

pod 'PonyDebugger', :configuration => 'Debug'

请注意,除非您已手动为它们指定构建配置,否则传递依赖项包含在所有配置中时。

Modular Headers

如果您想为每个 Pod 使用模块化标头,可以使用以下语法:

pod 'SSZipArchive', :modular_headers => true

另外,当你使用 use_modular_headers! 属性时,您可以使用以下方法从模块化标头中排除特定的Pod:

pod 'SSZipArchive', :modular_headers => false

Source

示例:

Specifying to first use the Artsy repository and then the CocoaPods Master Repository.

source 'https://github.com/artsy/Specs.git'
source 'https://github.com/CocoaPods/Specs.git'

默认按指定源全局搜索依赖项,也可以给特定依赖项指定源:

pod 'PonyDebugger', :source => 'https://github.com/CocoaPods/Specs.git'

在这种情况下,将仅搜索指定的源以查找依赖项,并忽略任何全局源。

Subspecs

通过名称安装Pod时,它将安装 podspec 中定义的所有默认 subspecs

您可以使用以下方法安装特定的 subspec

pod 'QueryKit/Attribute'

您可以指定要安装的子规范集合,如下所示:

pod 'QueryKit', :subspecs => ['Attribute', 'QuerySet']

依赖性也可以从外部来源获得。

使用本地路径文件

使用 path 选项

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

使用此选项,CocoaPods 将假定给定的文件夹是 Pod 的根目录,并将直接从 Pods 项目中的链接文件。这意味着您的编辑将持久保存到 CocoaPods 安装。

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

来自远程仓库根目录中的podspec

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

使用仓库 master 分支:

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

使用仓库其他分支:

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

使用仓库的某个 tag

pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :tag => '0.7.0'

或指定 commit

pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :commit => '082f8319af'

podspec 文件应该位于存储仓库的根目录中,如果该仓库没有 podspec 文件,则必须使用以下方法之一指定。

From a podspec outside a spec repository, for a library without podspec:

pod 'JSONKit', :podspec => 'https://example.com/JSONKit.podspec'

podspec

示例:

podspec
podspec :name => 'QuickDialog'
podspec :path => '/Documents/PrettyKit/PrettyKit.podspec'

target示例

Defining a target

target 'ZipApp' do
  pod 'SSZipArchive'
end

Defining a test target accessing SSZipArchive pod from its parent

target 'ZipApp' do
  pod 'SSZipArchive'

  target 'ZipAppTests' do
    inherit! :search_paths
    pod 'Nimble'
  end
end

Defining a target applies Pods to multiple targets via its parent target

target 'ShowsApp' do
  pod 'ShowsKit'

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

  # Has its own copy of Specta + Expecta
  # and has access to ShowsKit via the app
  # that the test target is bundled into

  target 'ShowsTests' do
    inherit! :search_paths
    pod 'Specta'
    pod 'Expecta'
  end
end

inherit!

设置当前目标的继承模式。

有效的模式:

  • :complete 继承父target所有行为

  • :none 不继续父target的行为

  • :search_paths 仅继承父target的搜索路径

示例:

target 'App' do
  target 'AppTests' do
    inherit! :search_paths
  end
end

Target configuration

platform

指定应为其构建静态库的平台,示例:

platform :ios, '4.0'
platform :ios

project

Specifies the Xcode project that contains the target that the Pods library should be linked with.

示例:

# This Target can be found in a Xcode project called `FastGPS`
target 'MyGPSApp' do
  project 'FastGPS'
  ...
end

# Same Podfile, multiple Xcodeprojects
target 'MyNotesApp' do
  project 'FastNotes'
  ...
end
project 'TestProject', 'Mac App Store' => :release, 'Test' => :debug

inhibit_all_warnings!

屏蔽来自 CocoaPods 库的所有警告。

您可以使用以下内容排除特定Pod被屏蔽:

pod 'SSZipArchive', :inhibit_warnings => false

use_frameworks!

Use frameworks instead of static libraries for Pods.

Workspace

This group list the options to configure workspace and to set global settings.

workspace

Specifies the Xcode workspace that should contain all the projects.

示例:

workspace 'MyWorkspace'

相关文章

  • Podfile语法参考(译)

    本文翻译自官方的Podfile Syntax Reference,也参考了之前一位博主的翻译,若翻译中有什么异议,...

  • Podfile语法参考(译)

    Podfile Podfile 是一个规范,描述了一个或多个 Xcode 工程中 targets 的依赖关系。 P...

  • Podfile语法参考

    1.官方说明:点击这里2.翻译请看简书:这里

  • CocoaPods的Podfile文件编写

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

  • Podfile语法参考(翻译)

    目录 Podfile 根选项 依赖关系 目标配置 工作空间 源 钩子 Podfile Podfile是描述一个或多...

  • CocoaPods详解3:.podfile语法参考

    https://www.cnblogs.com/lxlx1798/p/14587268.html[https://...

  • Podfile语法

    1.单个target依赖库 2.多个target依赖库 3.多个target依赖库高端写法 注意: (1) pla...

  • Podfile 语法

    Podfile 是描述一个或多个 Xcode 项目的目标的依赖关系的规范。Podfile文件可以非常简单: 一个更...

  • Podfile语法

    1.单个target依赖库 2.多个target依赖库 3.多个target依赖库高端写法 注意:(1) plat...

  • Podfile语法

    https://guides.cocoapods.org/syntax/podfile.html#podfile[...

网友评论

      本文标题:Podfile语法参考(译)

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