Demystifying LockFiles and CocoaPods

Vasudha Jha
The Engineering Gecko
2 min readDec 2, 2019

Only locks in life are what you think you know, but don’t.
Dennis Vickers

If you want to understand the basics of CocoaPods before jumping to Lockfiles, checkout out this blog. There, I have explained the basics of CocoaPods and why and how you should go about integrating them in your project.

What is Podfile.Lock?

According to CocoaPods.org,

A Podfile.Lock is generated after the first run of pod install, and tracks the version of each Pod that was installed.

You can think of it as a snapshot of exactly what CocoaPods has installed in your iOS project!

This leads us to the following question,

Why do you need a Podfile.Lock for version tracking when you can mention the pod versions in the Podfile ?

A Lockfile comes in handy when you are working with a team by making sure that all your files are in sync. Let’s understand how.

Say, you are integrating a specific version of pod in your project.

pod 'VanillaPod', '~1.5'

The latest version for that pod is 1.5.2 at that time.

When you run pod install, you’ll get the library with version 1.5.2 added to your project.

Say, the author of the library changed its version to 1.6.0. Since you didn’t run pod update, you will still have the version 1.5.2.

Your teammate, Jane, gets a copy of the project and runs a pod install. Without the Lockfile, CocoaPods will install the latest version of that pod available, i.e., version 1.6.0. If Jane starts using features that are in version 1.6.0, merging her changes into your project might cause the code to break.

This is where a Lockfile comes into picture.

If you have a Lockfile checked into your project, it would record the pod version you have installed.

LockfileVanillaPod: 1.5

As a result, when Jane gets a copy of your project and runs pod install, CocoaPods will check your Lockfile and install the version mentioned there, i.e., version 1.5 even though version 1.6.0 is the latest version available.

Sidenote:

If Jane runs a pod update on your repository, CocoaPods will install the latest version of the pod. It will also update the pod version number in the Lockfile. Hence, if you have been tracking your Lockfile under version control, you can exactly see what changes have been made and revert them if you want to revert to the previous versions.

--

--

Vasudha Jha
The Engineering Gecko

An engineer, artist and writer, all at the same time, I suppose.