How to Create a Swift CocoaPod swiftly

dependencies

Credit: xkcd

CocoaPods are an incredibly helpful tool for incorporating dependencies into your Xcode projects. But what if you want to create your own pod to share as an open-source project or for internal use? This is exactly where I am today and I decided to document my findings as a reference to myself and others.

I’m going to walk us through the creation of a project I’m working on called ASTimer. ASTimer will be a library for adding some cool functionality to Apple’s NSTimer class.

Step 1:

If you don’t already have CocoaPods installed, it’s as easy as installing a RubyGem:

$ gem install cocoapodslive streaming film Fifty Shades Darker 2017 online

This will tell RubyGems to go out and fetch the latest version of CocoaPods for you.

Step 2:

We’re going to use the pod command line tool in our pods directory:

If everything goes correctly, CocoaPods should say you’re ready to go with something like this:

Step 3:

Now we should setup the .podspec file (so CocoaPods knows what your project is about) and software license for the pod. The authorities at CocoaPods require that all pods include a software license if they’re to be permitted in the main trunk. I am personally a fan of the WTFPL myself, but use your own discretion.

Add a .podspec file:

Next, check to see if your Podspec is acceptable

Step 4:

Finally, we are able start coding our development pods and build an example in the pod example target

Here’s a link to the code I created for this project:  ASTimer

Step 5:

Once you’re happy with your Pod and its example code, you can tag a release and send it to the Cocoapods trunk.

If you haven’t already, you will need to register your machine so you can push to the Cocoapods trunk so other developers can access your pod.

Once you’re registered, you should be ready to tag your release and push it.

 


Also published on Medium.

Published by Andrew

Leave a Reply

Your email address will not be published. Required fields are marked *

12 − 4 =