Wow, that was easy.
What I cover here:
What is CocoaPods?
(Are you a JS dev who uses npm? An Android dev who uses Maven Central and Gradle? A Ruby dev who uses RubyGems? If so, CocoaPods is the Swift/Objective-C version of all those services.)
You are developing an iPhone, iPad, Apple Watch, Apple TV, or Mac app on a Thursday night. You are developing a new To-Do list app that calls an API to save the user's data. You browse GitHub to find this awesome library called Alamofire that makes it super easy to call an API using Swift. Alamofire sounds awesome! Now, how do you use it in your app? CocoaPods, that's how!
CocoaPods is a command-line tool that allows you to install code libraries, aka dependencies, into your XCode project to use in your app. CocoaPods contains hundreds of thousands of Swift and Objective-C dependencies that you can install into your XCode project right now. It makes it very easy to find, install, and update all of your dependencies so you can get on with building your app.
Why create a CocoaPod library?
Has this ever happened to you? You are sitting at your laptop, programming away inside of XCode creating the latest and greatest new iPhone app. Then, as you are half way into it you say, "Oh, I remember 3 months ago I wrote some code that I can reuse in this app." You proceed to open the GitHub repo for that app you wrote 3 months ago, find that file you wrote, and then you copy and paste that code into your new app you are working on now.
Instead of digging up old code and copy/pasting it, create a CocoaPod library instead. Then when you find yourself in this situation again where you want to use that code you wrote way back when, install your CocoaPods library in your XCode project and away you go!
I found myself needing to work with NSUserDefaults in my apps and tended to forget the API for how to use it. To help me, I wrote this code file, NSUserDefaultsUtil that allows me to work with NSUserDefaults easier. I have used this file in a half dozen different iPhone apps I have built. This is great and all, but becomes a huge pain once I decide to update my NSUserDefaultsUtil file. I had to go back and copy/paste this newly updated file into all of those half dozen apps I worked on previously. Now instead of copying/pasting into each app project, I created a CocoaPod library called iOSBoilerplate that contains NSUserDefaultsUtil for me. Anytime I want to update this file, I update the CocoaPod, push a new version out, then in each of my previous apps I can update to the latest CocoaPod version! So much better to manage!
How to create a CocoaPod?
Creating a CocoaPods library is really quick and easy. Here is a video I created on how to create a CocoaPods library from scratch, add your source code to it, test it, and release to the world allowing other projects to use it.
After you create your first CocoaPods library, send me a tweet with a link to it. I want to see what you create!
Subscribe to Live & Learn
Get the latest posts delivered right to your inbox