Creating your own CocoaPod library

Pratheesh Bennet
3 min readDec 29, 2021

--

Hi there!! We are going to see how to distribute your own open-source or private library using CocoaPods.

The key ingredients to distribute via cocoapods are relatively straightforward,

  1. The pod repo
  2. The pod spec file
  3. The LICENSE file
  4. The pod spec repo

The Pod Repo: This repo holds the actual code base of your library.

The pod spec file: The .podspec file holds details about where the source should be fetched from, what files to use, the build settings to apply, and other general metadata such as its name, version, and description. The .podspec should be present at the root level of the pod repo(the library codebase) that you are maintaining.

The LICENSE file: CocoaPods need a LICENSE file also to be maintained at the Pod Repo’s root level. CocoaPods do not accept libraries without a LICENSE file

The pod spec repo: For private libraries, to work with your collection of private pods, create your own Spec repo that contains the list of all available pods. This should be in a location that is accessible to all who will use the repo.

For open-source libraries, it is the repository on GitHub that contains the list of all available pods. Every library has an individual folder, which contains subfolders of the available versions of that pod.

Let’s see a sample step by step release of a library using cocoapods,

CircularProgressView is a cool library that displays circular progress.

  1. Prepare the pod spec of the library and add it at the root level of the cloned project folder, for more detailed info on the pod spec attributes please see here

2. Testing the podspec

You can test the syntax of your Podfile by linting the pod against the files of its directory, this won’t test the downloading aspect of linting.

On your cloned library codebase folder containing the podspec file simply run

pod lib lint

3. Create the PodSpec repo (Private library only)

Create a new repo called CircularProgressSpecs. Add the private spec repo to your cocoapods by running

pod repo add  CircularProgressSpecs https://github.com/PratheeshBennet92/CircularProgressSpecs.git

4. Tagging the version of your library

Once you have a release ready for your library you’ll need to make the corresponding tag to mark the release points. In your cloned repo of the library simply run,

$ git tag '1.0.0'
$ git push --tags

5. Pushing the library

To release open-source library you need to setup the cocoapods trunk. Please refer here for trunk setup. To releasepod trunk push CircularProgressView.podspec.

For private release: pod repo push CircularProgressSpecs CircularProgressView.podspec

6. CocoaPods installation

For private pods please specify the source of the specs repo in the podfile and simply give the podname and install.

For open-source pods simply give the podname and install.

Hope you found the sample helpful. Please reach me at pratheesh_db@hotmail.com for any help/queries.

References

--

--

Pratheesh Bennet

Product owner Falcon Forms (www.falconforms.app). Digitize your paperwork using Falcon Forms. Build and configure your own forms in an instant.