How to Create a Swift CocoaPod swiftly

Andrew Sowers
Feb 10, 2016 · 2 min read

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 cocoapods

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:

$ pod lib create ASTimer

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

Ace! you're ready to go!
We will start you off by opening your project in Xcode

open 'ASTimer/Example/ASTimer.xcworkspace'

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: do |spec| = 'ASTimer'
spec.version = '0.0.1'
spec.license = { :type => 'WTFPL' }
spec.homepage = ''
spec.authors = { 'Tony Million' => '' }
spec.summary = 'ARC and GCD Compatible timer Class for iOS and OS X.'
spec.source = { :git => '', :tag => 'v0.0.1' }
spec.source_files = 'ASTimer.{h,m,swift}'
spec.framework = 'SystemConfiguration'

Next, check to see if your Podspec is acceptable

$ pod lib lint ASTimer.podspec

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.

$ pod trunk register 'Andrew Sowers' --description='Andrew Sowers'

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

$ git add -A && git commit -m "Release 0.0.1."
$ git tag '0.0.1'
$ git push --tags
$ pod trunk push ASTimer.podspec

Originally published at Haiku Robot.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store