I recently wrote about how the perfect developer world should look like, where every line of code written is generic and bug free. Looking back at my code made me realize that I could very well put my words into action and start creating CocoaPods to get over the endless snippet copy-pasting that I went through to configure a recent project of mine.

Just to provide a bit of context, CocoaPods is a sort of facilitator that makes it easier to manage dependencies in your code. It's meant for iOS and OX X development, and allows you to save a lot of time that can be put on writing code instead of constantly managing it. Basically, it'll make dealing with the project a much easier and faster process.

But the question for which you're looking for an answer to is:

How do I create Cocoapods?

Ever since I found out about CocoaPods I've enjoyed using it, and the fact is that the whole iOS community is using it as well. However, I found out that the current resources and tutorials about CocoaPods make the task of creating one appear so much harder than it actually is.

So, to explain just how easy it is, here are the steps I ended up doing to turn my CameraManager (more about it here) project into a very simple CocoaPod and that you can replicate for your own projects:

Step 1 - Go to your project folder and execute:

pod spec create CameraManager

Step 2 - After reviewing the generated file, I was left up with the essence of podspec which is:

Pod::Spec.new do |s| s.name = "CameraManager" s.version = "1.0.3" s.summary = "This is a simple class to provide all the configurations you need to create custom camera view in your app. Just drag, drop and use." s.homepage = "https://github.com/imaginary-cloud/CameraManager" s.license = 'MIT' s.author = { "nelanelanela" => "[email protected]" } s.source = { :git => "https://github.com/imaginary-cloud/CameraManager.git", :tag => "1.0.3" } s.social_media_url = 'http://www.imaginarycloud.com/' s.platform = :ios, '7.0' s.requires_arc = true s.source_files = 'camera/CameraManager.swift' end

And here you should focus on the last line that specifies the source files of your CocoaPod. Make sure you include all of them, you'll get snippets for adding more than one file in the generated podspec, and make sure that you include the whole path to the file.

The other notice here goes to the s.source :tag, it's a tag you want users to download the repo with to match the version they want. Every time you create a new version of the repo you need to push the updated podspec file as well as the very same tag name you put in there to your own GitHub repo.

Step 3 - Run: pod spec lint CameraManager.podspec to see if the file you created will work and solve all the errors and warnings you'll get with the help of Google.

Step 4 - Push validated podspec file to your project repo.

Step 5 - Test on some random project if it works correctly with a podfile:

platform :ios, '7.1' pod 'CameraManager', :git => 'https://github.com/imaginary-cloud/CameraManager.git'

Step 6 - Create a trunk account if it's your first CocoaPod:

pod trunk register [email protected] 'Orta Therox' --description='macbook air'

Step 7 - Finally, from the root directory of you project, push the created CocoaPod to the main repo:

pod trunk push CameraManager.podspec

After a few minutes, enjoy your opensource library that's easy to use for all iOS developers out there!

Ready for a UX Audit? Book a free call

Found this article useful? You might like these ones too!