Reprint: Use pod install or pod update?

Source: Internet
Author: User

Reprint: Http://www.jianshu.com/p/a977c0a03bf4 Introduction:

Many people start using cocodpods and think that pod install is just the first time you use Cocoapods to build a project, and then you use Pod Update, but it's not actually the case.

In simple terms, it is:

1. Install a new library using pod install, even if you have podfile in your project and have already performed the Pod Install command, you should use pod install even if you are adding or removing a library.

2. Use pod Update [podname] only when you need to update the library to the updated version.

Detailed description: Pod install:

This is the first time you use pods in a project, and it is used every time you edit your podfile (add, remove, update).

Each time you run the pod Install command, the version of each library you install is written in the Podfile.lock file while you download and install the new library. This file records the version number of each of your installation libraries, and locks those versions.

When you use pod install it only resolves dependencies between those libraries that are inside pods but not within the Podfile.lock file. For those libraries listed in Podfile.lock, it will download the explicit version in Podfile.lock, and will not check if the library has a new version. For libraries that are not yet inside the Podfile.lock, you will find podfile that describe the corresponding version (for example: Pod "Mypod", "~>1.2").

Pod outdated:

When you run the pod outdated command, cocoapods lists all the newer versions of the library (those that are currently installed) in the Podfile.lock. This means that if you run Pod update podname, if the library has a new version, and the new version still conforms to the podfile limit, it will be updated.

Pod Update:

When you run the pod Update podname command, Cocoapods will help you update to the new version of the library without having to consider the limitations in the Podfile.lock, which will update to the new version of the library whenever possible, as long as it conforms to the version limits in Podfile.

If you run Pod Update and do not follow the name of the library, Cocoapods will update every podfile inside the library to the latest version possible.

Correct usage:

You should use Pod update podname to update only a particular library (check for new versions and update to new versions whenever possible). Corresponding, you should use pod install, this command will not update those libraries that have already been installed.

When you add a library to your podfile, you should use pod install instead of pod Update, which installs the library and does not need to update other installed libraries.

You should use Pod Update to update a particular library, or all libraries (in the podfile limit).

Submit your Podfile.lock file:

In this reminder, even if you have always been, do not commit your Pods folder to the remote repository, you should also commit and push to the remote repository.

Otherwise, it will destroy the entire logic, without the Podfile.lock limit the version of the library in your pods.

Example:

The following examples illustrate the use of each scenario.

Scene 1:user1 created a project

User1 created a project and wanted to use the three libraries of a, B, C, so he created a podfile that contained the three libraries and ran pod intall.

This will install a, B, C three libraries into this project, assuming that our version is 1.0.0.

So Podfile.lock tracks and records the three libraries of a, B, C, and the version number 1.0.0.

By the way: Since this project is the first time to run pod install, and the Pods.xcodeproj project file does not exist, so this command will also create pods.xcodeproj as well as the. Xcworkspace project file, which is only a side effect of this command, not the main purpose.

Scene 2:user1 added a library

After that, User1 adds a library d to the Podfile file.

Then he should run the Pod install command. So even if the developer of Library B publishes a new version of B, 1.1.0. However, as long as it is released after the first execution of the pod install, the version of B is still 1.0.0. Because User1 only wants to add a new library D, you do not want to update library B.

This is where many people are prone to error because they are using pod update here because they want to "update my project to a new library." Be careful here!

Scene 3:user2 added to this project

Then, User2, a person who had not been involved in the project before, joined. He clones a copy of the warehouse and uses the pod install command.

Podfile.lock content will ensure that User1 and User2 will get exactly the same pods, provided Podfile.lock is committed to the GIT repository.

Even though the version of library C has been updated to 1.2.0,user2, the 1.0.0 version of C will still be used, because C has already been registered in Podfile.lock, and the 1.0.0 version of C has been locked by Podfile.lock.

Scenario 4: Check for a new version of a library

After that, User1 wanted to check if there was an update available in pods, and he executed the pod outdated, which was listed after the command was executed: B has the 1.1.0 version, C has the 1.2.0 version.

At this point, User1 intends to update library B, but does not update library C, so do pod update B, so that the B is updated from 1.0.0 to 1.1.0 (while updating the podfile.lock version of B), at this time, C is still 1.0.0 version, will not be updated.

Using explicit versions in Podfile is not enough

Some people think that it is clear that the version of a library in podfile, such as pod ' A ', ' 1.0.0 ', is sufficient to ensure that all people in the project will use the exact same version.

At this point, they may feel that if I add a new library at this time, I will not update the other libraries with Pod update because the other libraries are already limited to a fixed version number.

In fact, this is not enough to ensure that the User1 and User2 versions of the Pods library will be exactly the same.

A typical example is if library A has a dependency on the library A2 (declared in A.podspec: Dependency ' A2 ', ' ~> 3.0 '), if so, using pod ' a ', ' 1.0.0 ' in your podfile, It is true that both User1 and User2 use the same version of library A (1.0.0), however:

Finally User1 may use A's dependent library A2 version of 3.4 (because 3.4 is the latest version used by User1 at the time), but User2 uses a library A2 version of 3.5 (assuming A2 's developers have just released A2 's new version 3.5).

So there is only one way to ensure that every developer of a project uses the same version of the library, that is, each computer uses the same podfile.lock, and uses the pod install and pod update appropriately.



Wen/ios_hxy (author of Jane's book)
Original link: http://www.jianshu.com/p/a977c0a03bf4
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".

Reprint: Use pod install or pod update?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.