podfile 常见语法2

The Podfile is a specification that describes the dependencies of the targets of one or more Xcode projects.A Podfile can be very simple:

target'MyApp'

pod 'AFNetworking', '~> 1.0'

An example of a more complex Podfile can be:

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.pod_targets.each do |target|
    puts "#{target.name}"
  end
end

常见写入Podfile的写法:


xcodeproj 'CacheDemo.xcodeproj'

platform:ios,'7.0'

pod 'FMDB'

pod 'AFNetworking','~>2.6'

pod install vs. pod update

Introduction




Many people starting with CocoaPods seem to think pod install is only used the first time you setup a project using CocoaPods and pod update is used afterwards. But that's not the case at all.

The aim of this guide is to explain when you should use pod install and when you should use pod update.



TL;DR:

  • Use pod install to install new pods in your project. Even if you already have a Podfileand ran pod install before; so even if you are just adding/removing pods to a project already using CocoaPods.
  • Use pod update [PODNAME] only when you want to update pods to a newer version.

<Detailed presentation of the commands

Note: the vocabulary of install vs. update is not actually specific to CocoaPods. It is inspired by a lot of other dependency managers like bundlerRubyGems or composer, which have similar commands, with the exact same behavior and intents as the one described in this document.

<


pod install

This is to be used the first time you want to retrieve the pods for the project, but also every time you edit your Podfile to add, update or remove a pod.

  • Every time the pod install command is run — and downloads and install new pods — it writes the version it has installed, for each pods, in the Podfile.lock file. This file keeps track of the installed version of each pod and locks those versions.
  • When you run pod install, it only resolve dependencies for pods that are not already listed in the Podfile.lock.
    • For pods listed in the Podfile.lock, it downloads the explicit version listed in the Podfile.lock without trying to check if a newer version is available
    • For pods not listed in the Podfile.lock yet, it searches for the version that matches what is described in the Podfile (like in pod 'MyPod', '~>1.2')

<


pod outdated

When you run pod outdated, CocoaPods will list all pods which have newer versions than the ones listed in the Podfile.lock (the versions currently installed for each pod). This means that if you run pod update PODNAME on those pods, they will be updated — as long as the new version still matches the restrictions like pod 'MyPod', '~>x.y' set in your Podfile.

<pod update

When you run pod update PODNAME, CocoaPods will try to find an updated version of the pod PODNAME, without taking into account the version listed in Podfile.lock. It will update the pod to the latest version possible (as long as it matches the version restrictions in your Podfile).

If you run pod update with no pod name, CocoaPods will update every pod listed in your Podfile to the latest version possible.

<Intended usage

With pod update PODNAME, you will be able to only update a specific pod (check if a new version exists and update the pod accordingly). As opposed to pod install which won't try to update versions of pods already installed.

When you add a pod to your Podfile, you should run pod install, not pod update — to install this new pod without risking to update existing pod in the same process.

You will only use pod update when you want to update the version of a specific pod (or all the pods).

<Commit your Podfile.lock

As a reminder, even if your policy is not to commit the Pods folder into your shared repository, you should always commit & push your Podfile.lock file.

Otherwise, it would break the whole logic explained above about pod install being able to lock the installed versions of your pods.

<Scenario Example

Here is a scenario example to illustrate the various use cases one might encounter during the life of a project.

<Stage 1: User1 creates the project

user1 creates a project and wants to use pods A,B,C. They create a Podfile with those pods, and run pod install.

This will install pods A,B,C, which we'll say are all in version 1.0.0.

The Podfile.lock will keep track of that and note that A,B and C are each installed as version 1.0.0.

Incidentally, because that's the first time they run pod install and the Pods.xcodeproj project doesn't exist yet, the command will also create the Pods.xcodeproj and the .xcworkspace, but that's a side effect of the command, not its primary role.

<Stage 2: User1 adds a new pod

Later, user1 wants to add a pod D into their Podfile.

They should thus run pod install afterwards, so that even if the maintener of pod B released a version 1.1.0 of their pod since the first execution of pod install, the project will keep using version 1.0.0 — because user1 only wants to add pod D, without risking an unexpected update to pod B.

That's where some people get it wrong, because they use pod update here — probably thinking this as "I want to update my project with new pods"? — instead of using pod install — to install new pods in the project.

<Stage 3: User2 joins the project

Then user2, who never worked on the project before, joins the team. They clone the repository then use pod install.

The contents of Podfile.lock (which should be committed onto the git repo) will guarantee they will get the exact same pods, with the exact same versions that user1 was using.

Even if a version 1.2.0 of pod C is now available, user2 will get the pod C in version 1.0.0. Because that's what is registered in Podfile.lock. pod C is locked to version 1.0.0 by the Podfile.lock (hence the name of this file).

<Stage 4: Checking for new versions of a pod

Later, user1 wants to check if any updates are available for the pods. They run pod outdatedwhich will tell them that pod B have a new 1.1.0 version, and pod C have a new 1.2.0 version released.

user1 decides they want to update pod B, but not pod C; so they will run pod update B which will update B from version 1.0.0 to version 1.1.0 (and update the Podfile.lock accordingly) but will keep pod C in version 1.0.0 (and won't update it to 1.2.0).

<Using exact versions in the Podfile is not enough

Some might think that by specifying exact versions of their pods in their Podfile, like pod 'A', '1.0.0', is enough to guarantee that every user will have the same version as other people on the team.

Then they might even use pod update, even when just adding a new pod, thinking it would never risk to update other pods because they are fixed to a specific version in the Podfile.

But in fact, that is not enough to guarantee that user1 and user2 in our above scenario will always get the exact same version of all their pods.

One typical example is if the pod A has a dependency on pod A2 — declared in A.podspec as dependency 'A2', '~> 3.0'. In such case, using pod 'A', '1.0.0' in your Podfile will indeed force user1 and user2 to both always use version 1.0.0 of the pod A, but:

  • user1 might end up with pod A2 in version 3.4 (because that was A2's latest version at that time)
  • while when user2 runs pod install when joining the project later, they might get pod A2 in version 3.5 (because the maintainer of A2 might have released a new version in the meantime).

That's why the only way to ensure every team member work with the same versions of all the pod on each's computer is to use the Podfile.lock and properly use pod install vs. pod update.

区别在这里:pod install会按照 pod 文件指定的版本安装,而pod update会安装最新版本。如果不是特别需要指定版本的话,一般情况下用pod update就可以啦。

https://guides.cocoapods.org/using/pod-install-vs-update.html

时间: 2024-08-01 11:38:04

podfile 常见语法2的相关文章

Podfile 常见语法

source  'URL' : 指定镜像仓库的源 platform : ios,  '6.0'  : 指定所支持系统和最低版本 inhibit_all_warnings! :屏蔽所有warning workspace '项目空间名': 指定项目空间名 xcodeproj '工程文件名':指定xcodeproj工程文件名 下面都是引入库的语句: pod  '库名',   :   引入库,什么版本都可以(一般就是最新版本了) pod  '库名', '版本'  :  引入指定版本的库,下面的运算符可以

玩转Podfile

前言 经常使用CocoaPods来管理iOS项目中的第三方库,但是我们要使用CocoaPods来管理第三方库,前提是要写好Podfile文件,通过这个文件来配置第三方库与项目之间的依赖.版本等信息. 但是,我相信很少有人完整地学习过Podfile的语法规则,包括笔者在写本篇文章之前.今天,请大家与笔者一起来完整地学习Podfile官方教程. 之前一直想写来着,因为包括笔者在内并没有深入学习过它的使用.如果对之不够了解,如何能做到善用之.因此,下面一起来探讨探讨吧! 什么是Podfile 官方只有

《日志管理与分析权威指南》一2.2.2 日志语法

2.2.2 日志语法 任何格式的日志文件都具有语法,日志语法在概念上与语言(如英语)语法相似.人类语言语法中的句子通常包含一个主语.一个谓语.有时还包含一个表语,当然还有补语和定语.句子的语法涵盖句子成员之间的关系和他们的含义.需要注意的是,语法并不涉及消息的内容.换句话说,语法处理的是如何构造我们所要表述的内容,而不是我们使用的具体词语.那么,在日志消息的环境下语法又有什么意义呢?当然,每条日志消息都有表征它的结构.一些类型的日志消息自身具有人类语言的部分语法,日志消息每部分由各种类型的信息模

正则表达式实现资料验证的技术总结

资料验证无论在C/S还是在B/S中的使用都是非常普遍的, 过去大家喜欢用一堆的 IF...else...判断输入的内容是否满足要求. 如今很多语言都支持正则表达式, 它定义了一套自己的语法规则 (常见语法包括:字符匹配.重复匹配.字符定位.转义匹配和其他高级语法)来完成各种资料的验证, 功能之强大在我看来几乎到了无敌的地步. 但是据我所了解(呵呵, 很可能是坐井观天, 如果有让哪位不爽请原谅我没见过世面)很多很多自称为(或他称)程序员的在平时的工作中很少用到正则表达式, 不知道什么原因, 可能是

跟老男孩学Linux运维:Shell编程实战.

Linux/Unix技术丛书 跟老男孩学Linux运维: Shell编程实战 老男孩 著 图书在版编目(CIP)数据 跟老男孩学Linux运维:Shell编程实战 / 老男孩著. -北京:机械工业出版社,2017.1 (Linux/Unix技术丛书) ISBN 978-7-111-55607-7 I. 跟- II. 老- III. Linux操作系统 IV. TP316.85 中国版本图书馆CIP数据核字(2016)第313248号 跟老男孩学Linux运维:Shell编程实战 出版发行:机械工

Vim的安装与配置

vim的安装 Ubunto安装vim包 Ubunto使用如下命令即可安装vim sudo apt-get install vim vim-scripts vim-doc 1 1 其中vim-scripts是vim的一些基本插件,包括语法高亮的支持.缩进等等. 当然我也可以使用其他的安装命令 sudo apt-get install vim sudo apt-get install vim-gtk 等等,其实本质都是相同的,只是安装的包多包少的问题 其他Linux发行版用户亦可使用自家的包管理器进

跟老男孩学Linux运维:Shell编程实战1.3 如何才能学好Shell编程之“老鸟”经验谈

1.3 如何才能学好Shell编程之"老鸟"经验谈 学好Shell编程的核心:多练→多思考→再练→再思考,坚持如此循环即可! 从老男孩IT教育毕业的一名学生曾在工作多年后返校分享了一篇"如何学好Shell编程"的讲稿,经过老男孩的整理后和读者分享如下. (1)掌握Shell脚本基本语法的方法 最简单有效的方法就是将语法敲n+1遍.为什么不是n遍呢?因为这里的n指的是你刚开始为掌握语法而练习的那些天(21天法则),而1则是指在确定掌握语法后每天都要写一写.想一想,至少

《R语言数据分析》——3.2 聚集

本节书摘来自华章出版社<R语言数据分析>一书中的第3章,第3.2节,作者盖尔盖伊·道罗齐(Gergely Daróczi),潘怡 译,更多章节内容可以访问"华章计算机"公众号查看. 3.2 聚集 最直接的数据汇总方法应该是调用stats包的aggregate函数,该函数能支持以下我们期望的功能:通过分组变量将数据划分成不同的子集,并分别对这些子集进行统计汇总.调用aggregate函数的最基本方法之一是传递待聚集的数值向量,以及一个因子变量,该因子变量将定义参数FUN的值,

自定义 mrtg 数据

mrtg 工作原理 1. 利用 snmp 返回数据 2. 利用 自定义脚本进行数据返回 example: 希望监控当前 mysql  query cache 使用中的内存大小. 默认状态下, mrtg 希望返回 4 条数据 1. 数据变量1 例如 input 流量 2. 数据变量2 例如 output 流量, 3. uptime 4. 对应目标名称, 例如主机名, ip 等资料 由于 query cache 不存在多变量返回, 则, 随便返回一个变量则可 脚本返回效果如下: [root@stat