Everything you need to know about Cocoapods in iOS

Ali Jaber
3 min readJun 10, 2021

Cocoapods is a centralized dependency manager* for both Swift and Objective c, it contains thousands of libraries and is used in more than 1 million app. It makes your app management easier, it saves a lot of time in removing, adding or updating any library inside your app.

Installing Cocoapods:

Its easier than you thought, just open terminal and type the following command:

Second step will be to run the following command after switching to your project file*:

this will create a pod file inside your project file, now choose whatever libraries you want to add to your project, and add them under the “#Pods for my Project” as shown below:

go back to terminal and run the following comment:

After success, you will find a new file with .xcworkspace extension in your project file. start using this instead of the .xcodeproj.

Some pros of using cocoapods:

  • easy to use.
  • You can easily find dependencies on the official Cocoapods website.
  • If a dependency is relied on another dependency, cocoapods handle this for you.
  • Almost every framework supports cocoapods.

Some Disadvantages of using cocoapods:

  • Build time is slower, since every time you build your projects, all dependencies are also built.
  • Hard to remove once it's integrated.
  • If something fails in cocoapods, the whole projects stop building.

Example of a podfile after adding some dependencies to the podfile:

pods inside the .pod file under the # Pods For ‘App name’

Removing Cocoapods From your project

Integrating pods into your project was very easy, unlikely, de-integration needs more time and more manual work.

  • open terminal and run “pod deintegrate”
  • Pods directory, Podfile.lock and app.xcworkspace should be removed, if not, remove them manually by deleting these files.
  • Go to ‘build phases’, delete all script added by Cocoapods, like Embeded pods frameworks, mainfest.lock, also remove the pods from the ‘link binary with libraries’, also dont forget to remove the pods from ‘frameworks, libraries , embeded conted’ in the general tab.

Centralization means having a single source for finding and downloading frameworks and libraries. Cocoapods is centralized because it owns a single repository on Github.

Carthage is decentralized because there isnt a single repository for finding dependencies.

I hope you enjoy this article, please let me know if you have any questions and feel free to add any comment.

--

--

Ali Jaber

iOS Engineer with more than 3 years experience in developing mobile apps in both swift and objective C for both local and international customers