Making Your Own CocoaPods— Part 1

Bharghav Kumar
3 min readFeb 24, 2019

Introduction

CocoaPods is a dependency management tool for the ObjC and Swift projects which provides a standard format for managing external libraries. It ultimately focuses to create a more centralised ecosystem to improve distribution and integration of third-party code into Xcode projects. It can also use to reduce big application into modules by segregating reusable code, utilities, extensions and so on as seperate library to utilize in any other projects. In this story, I’m going to demonstrate step by step to create and distribute cocoa pods into three sequel parts.

Story Portfolio

  • Installation
  • Private Spec Repo
  • Making Own Cocoapod
  • Own Cocoapod Distribution
  • Private CocoaPod Utilization
  • Conclusion

Installation

CocoaPods is built with RUBY which will be installable with the default Ruby available in macOS and runs from the command line. Using the default Ruby installation will require to use sudo when installing gems.

$ sudo gem install cocoapods

For sudo-less installation, please refer to this guide.

If encounter any problems during installation, please visit this guide.

Private Spec Repo

Spec Repo is a single source repository to work with the collection of private pods which means it includes all the information about each private pod. Make sure that every team member should have access to this repository and they should add this repository to their local cocoa pods directory

cd ~/.cocoapods/repos/REPO_NAME

to be able to use require pods in their respective projects. It needs to be created once for all the pods. It will automatically update with the procedure of any pod creation or updating. Let’s jump into spec repo creation process.

Step 1

Log in to any source control management tool (i.e Github, Gitlab or Bitbucket) which supports .git projects.

Step 2

Creating a New Repository

Create a new repository with a private option and name your spec repository. Remaining fields namely description, initialize with README, add .git ignore and add licence are optional. So the decision is yours to opt. For the demo, I created a repository named as my_privateSpec

Step 3

Open up the terminal for running following command to add spec repository into the local cocoapods directory which was created at the time of cocoapods installation. Make sure that every team member should do this step to work with or to utilize the pods.

pod repo add [SPEC_REPO_NAME] [REPO_URL]

As per demo, command seems like

$ pod repo add my_privateSpec https://github.com/cbk2604/my_privateSpec.git

If it needs to check everything is done smoothly or not, run following commands and check spec repository added into the local cocoapods directory.

$ cd ~/.cocoapods/repos
$ ls

Once the podspec repository is ready, we can move forward to create and distribute cocoapods in the next part.

Hope this series of stories will help you to create your own cocoapod library if you have any troubles and suggestions please mention in the comments and reach me out on my mail (ID: cbk2604@gmail.com) as well. Good luck my friends will see you in the next part. Keep following me.

--

--