How to Create your Private Library (Pod) with CocoaPods

Ziad Tamim
4 min readNov 11, 2016

CocoaPods is a dependency manager written in Ruby. If you don’t know about it but have been writing Ruby in the past, its syntax used in the Podfile in which you declare all your dependencies without too much of a hard time.

You can actually use CocoaPods for a specific application’s dependencies, meaning you can use it to split your big application in multiple modules and let CocoaPods handle the merge. In this tutorial, we’ll demonstrate how to create your own private library using Cocoapods for Internal/In-House use.

Install CocoaPods

As you might think, CocoaPods is a Ruby gem which means it can be installed using the following command:

For more information about Cocoapods installation check out their documentation.

Take a Look at Our App

Before we move onto the creation of our private pod, let’s take a look at what we’ll build.

Our library for this tutorial is called Snorlax which has a single class that mostly do nothing other than making him sleep for a random amount of time. I am sure that your library will be much interesting.

It’s a pretty useful code to get nowhere with your library :)

Create our Private Library

Now, It’s time to create our private pod. To do this you’ll need to run the following command:

Once this command is entered, you will get asked a series of questions.

  • When you’re asked what language you want to use, answer Swift.
  • When asked if you’d like to include a demo application, answerYes.
  • When asked which testing framework to use, answer None.
  • Answer No to the prompt regarding view based testing.

By now, Xcode should have already opened your brand new project ready for you to work on.

Adding functionalities

You now have the basic of a pod, but it doesn’t do anything yet. It’s time to add some functionalities by simply creating a new swift file called Snooze.swift under Pods/Development Pods/Snorlax/Pod/Classes/and past the code demonstrated in the previous section, then delete the file ReplaceMe.swift

Cool!! Try now to build your project and check if there are any issues related to swift 3 in order to go to the next step.

Checking the Podspec File

Before committing the Podspec file to our private repository we can test from the project directory by running the following command:

This should output the following:

The tool tells you that there are two things that need to be fixed in the .podspec file:

  • add more information to the summary
  • specify a URL for the pod’s homepage

Updating Your Pod’s Metadata

For fixing the issues mentioned on the previous section, open Snorlax.podspec available under Snorlax/Podspec Metadata/ as shown below:

Change the summary to:

Next, browse to Github or Bitbucket and create a private repository for our library then past the url given.

The next step in the initial project setup is to commit the changes and push everything to your created GitHub or Bitbucket remote repository. The following steps should do the trick:

Assuming everything passes we can make the final commit of the changes to the repository, create the tag and push it to the repository.

If all went smoothly and you now have a Git source controlled Snorlax library project ready. You are now ready to create a CocoaPod podspec for the project and continue developing your CocoaPod-enabled library project.

Setup Your Specs Repo

All the upcoming setup will pay off as you will have an established, repeatable process for setting up in-house libraries for your iOS app development. Adding more private shared libraries as you need them becomes straightforward.

Login to Github or Bitbucket and create a new private repository named PrivateTrunk to manage all your private libraries. Next, run the following command with the URL newly created:

Deploying your library

The final step is to push the Podspec to the private trunk service. You do this by executing the following command from the command line:

Use the library

That’s it, now you should be able to install your library through by editing your podfile, adding the source of your private repo at the top and the standard cocoapods source

Add the library normally.

Summary

After going through this tutorial, I hope that you now understand how to create your own private libraries. For your reference, you can download the complete Xcode project from here. As always, leave me a comment, share your thought about the tutorial and don’t forget to follow me for more tutorials.

--

--

Ziad Tamim

I’m an iOS Software Engineer. I can help you build and grow your next product. hey@byziad.com