Up next:

CocoaPods Private Publish

In this lesson

In some cases, you may not want to share your precious code abstracted into its library with the rest of the world. CocoaPods does have support for creating, sharing, and managing private pods and here is how you do it.

Kyle's Series

Transcript

Tap on time to skip ahead

0:11

0:11

Hello world, Kyle here with brax.tv and let’s talk about how to publish your very own custom library in Swift or Objective-C to CocoaPods, but not really to CocoaPods, but using CocoaPods to publish it privately for only you use or only those with access to use.

0:30

0:30

So a couple things you need to make sure you’re doing before you actually set up this private pod is to make sure that you are registered with CocoaPods via Trunk. Now Trunk is just a way to authenticate the current user, which would be you, and the device that you’re working on. And you just use this command here to register your email, name, and then a short description of the device that you’re on. And once you’ve done that registered, you also need to make sure that the source of your library is available and accessible to those who you want for anything you want to allow them to use this pod.

1:08

1:08

And by publishing privately, it’s just a way to manage versioning and installs of this private library using CocoaPods rather than setting it all up manually or doing something else, I don’t know. And then once you have those two things, you need to navigate to the directory in which your podspec is. And even though it’s a private repo, you do need a podspec still. So just navigate to that directory. And you want to use this command pod repo add REPO_NAME, which you replace with the custom name of the pod repository for your library, and then the SOURCE_URL, whether it’s on GitHub or really anywhere else on the internet.

1:50

1:50

And within this repository, you need to make sure that you are using a folder structure like this as this is the way behind the scenes that CocoaPods manages and stores the podspec for anyone to use. And since this is a private source and technically not being posted to the typical public CocoaPods domain, wherever that is, you need to mimic that same folder structure within your repo. And you can check that using something called pod repo lint. So that when you do run this push command here, after we’ve set up this private repo, when you push it, it’s going to run the lint on this repo. And again, replace the repository name with the name for the podspec repository and then actually pass in the name of the podspec. And assuming that you’ve set up the repository correctly and your podspec correctly, this command, I guess I should mention, will run pod spec lint as it says here, which is a separate command than pod repo lint. And as instead of checking the entire private repository, it’s just going to check the podspec.

2:57

2:57

And I know that’s kind of confusing, I will add links to the specific documentation page on CocoaPods.org. They have all of the instructions here as well as plenty of examples to look at and compare to when working with a private CocoaPod. But assuming that that private pod repo push command ran successfully and both lint checks passed successfully, then all of those with access to your podspec and the source will be able to install this private CocoaPod via CocoaPods.

3:30

3:30

You will have to, instead of defining the pod in your podfile using pod ‘POD_NAME’, you actually use the source descriptor and then pass in the URL to the pod repository. And then assuming that this computer and this user has access to that URL, then CocoaPods will install that URL as it would any other CocoaPod to whatever project trying. That’s how you publish CocoaPod for private use.