CocoaPods: creating your first pod

Matheus Freitas Venosa
Outsmart Digital
Published in
5 min readNov 1, 2018

Do you want to have your own lib? Do you like iOS development? Do you like swift? This is for you!

Here you're going to find simple steps to create your first pod and use it for anything you want!

1. Create a git repository

It doesn't matter which platform you're going to use, the only requirement is the git. Im using github in this tutorial.

The first thing you're going to do is create your repository.

Creating the pod-tutorial repo

After that you'll have the repository, you can follow the platform tutorial to clone and use the repo.

Now I have my local and remote repositories created.

2. Creating your pod project

The CocoaPods gives you a very simple way to setup a pod project, with a simple command:

 pod lib create [POD_NAME]
pod lib create

After answering the questions, a fresh new project will be created for you!

The pod_tutorial.podspec we're going to talk later, lets focus on the other ones:

  • Example for pod_tutorial: this is the folder that contains a real app to test the library you're developing. So, when you run the project the code in here will be executed.
  • ReplaceMe.swift: this is your pod content. Anything that will be used in your library will be in the pod-tutorial folder, side be side with the "ReplaceMe.swift".

Now, let's talk about the podspec…

3. Edit your podspec file

This file contains the specifications of your pod, let's talk about it's properties:

A lot of the properties doesn't need a explanation, so I'll focus on the most important ones:

  • s.license → This is the type of license your pod will use. Just keep this way! (I'm not explaining this in this tutorial, in google you can find more about this)
  • s.source → This is the url with your source code. The :tag means that it will link the version of the podspec with a tag (with the same name!!!) inside the git repository.
  • s.source_files → This is the place where your lib files are. ATTENTION! Open the finder and check this path!!! The xcode creates virtual folders that aren't there!
  • s.resource_bundles → different types of resources that you're using.
  • s.resources → the actual resources
Illustration of resources/resource_bundle

You can add dependencies and frameworks as well:

Example of frameworks/dependencies

4. Let's test our podspec

To see if you did everything right run the following command:

pod lib lint [POD_NAME].podspec

AND ….

You're probably going to fail because of the warnings

You have two options here:

  • Fix the podspec and try again
Now it works :)
  • Put a special tag to ignore the warnings
pod lib lint [POD_NAME].podspec --allow-warnings

5. Making a func

Crate a Speaker.swift file and delete the ReplaceMe.swift:

And inside the file:

6. Using your func

To use anything you develop inside the pod-tutorial you must install it. So, enter in the Example folder(where the test app is) and do:

This will install your pod (don't forget to build the project in the xcode!)

  • obs: the projects with the "-" character will use "_"

Now, modify the ViewController inside the Example:

Run the project!!

Aaaaand… pan pan pan pan

It works!!!

7. But how i'm going to use it in another project??

First, you need to upload everything to the remote repository and add the tag.

This will commit everything and create the tag (with the same name of your podspec version).

You can check the tag in your git platform, open your commit and it will be there.

Now, you must add and push your pod repo, doing:

pod repo add [POD_NAME] [GIT_URL]
pod repo push [POD_NAME] [POD_NAME].podspec

Now you can point to your remote pod in any podfile using the github url:

In the podfile
pod install

After all this you can finally use your lib!!! :) :)

Thanks for the patience!!

--

--

Matheus Freitas Venosa
Outsmart Digital
0 Followers
Writer for

I'm a software engineer and I love technology.