文章目录

    • 官网地址
    • 什么是Podfile
    • 迁移从0.x 到 1.0
    • 指定pod版本
    • 使用计算机本地文件夹中的文件。
    • 从库repo根目录中的一个播客规范。
    • 外部资源
    • 写在最后

官网地址

官网介绍

什么是Podfile

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

一个Podfile可以非常简单,这增加了一个单一的目标:

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

如果希望多个目标共享相同的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

迁移从0.x 到 1.0

我们有一篇博客文章详细解释了这些变化。

指定pod版本

在开始一个项目时,您可能希望使用最新版本的Pod。如果是这种情况,只需忽略版本需求。

pod 'SSZipArchive'

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

pod 'Objection', '0.9'

除了没有版本或特定的版本之外,还可以使用逻辑操作符:

  • ‘> 0.1’ Any version higher than 0.1(’> 0.1’任何高于0.1的版本)
  • ‘>= 0.1’ Version 0.1 and any higher version(’>= 0.1’版本0.1和任何更高版本)
  • ‘< 0.1’ Any version lower than 0.1(’< 0.1’小于0.1的任何版本)
  • ‘<= 0.1’ Version 0.1 and any lower version(’<= 0.1’版本0.1和任何更低的版本)

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

  • ‘~> 0.1.2’ Version 0.1.2 and the versions up to 0.2, not including 0.2 and higher(’~> 0.1.2’版本0.1.2和0.2以内的版本,不包括0.2及以上版本)
  • ‘~> 0.1’ Version 0.1 and the versions up to 1.0, not including 1.0 and higher(’~> 0.1’版本0.1和版本到1.0,不包括1.0和更高)
  • ‘~> 0’ Version 0 and the versions up to 1.0, not including 1.0 and higher(’~> ‘版本0和版本到1.0,不包括1.0和更高)

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

  • Semantic Versioning(语义版本控制)

  • RubyGems Versioning Policies(RubyGems版本管理策略)

  • 谷歌有一个很棒的视频介绍了它是如何工作的:(天朝不翻墙打不开 – -!) “CocoaPods and the Case of the Squiggly Arrow (Route 85)”.

  • 注意,视频中关于~> 1的信息是不正确的。

使用计算机本地文件夹中的文件。

如果您想要开发一个Pod及其客户端项目,您可以使用:path。

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

使用这个选项,CocoaPods将假定给定的文件夹是Pod的根目录,并将从那里直接链接到Pods项目中的文件。这意味着您的编辑将在安装CocoaPods期间保持。引用的文件夹可以是您最喜欢的SCM的签出,甚至是当前repo的git子模块。

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

从库repo根目录中的一个播客规范。

有时你可能想要使用一个Pod的前沿版本,一个特定的修订或你自己的叉子。如果是这种情况,您可以通过pod声明来指定。

回购主分支的使用:

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

使用回购的不同分支:

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

使用回购的标签:

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的根目录中,如果这个库的repo中还没有一个podspec文件,那么您将不得不使用下面部分中列出的方法之一。

外部资源

  • Non-trivial Podfile in
    Artsy/Eigen(非平凡的Podfile在艺术/特征)
  • Podfile for a Swift project in
    Artsy/Eidolon(在一个Swift项目的播客文件艺术/的精灵)

写在最后

首页/使用Podfile/Podfile

CocoaPods是开源项目通过发送一个pull request来帮助我们改进这些指南

本文地址:https://blog.csdn.net/baicai_520/article/details/108703946