Create a Pod in Cocoapods
Aug 28, 2018
This is a simple guide to upload your first Pod to Cocoapods.
CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects and I'm sure that you have a lot of code you are proud of and would like to share with the world.
First steps - Install CocoaPods
$ sudo gem install cocoapods
Upload your code to GitHub
Upload your code/project to github. Here you can find an example of a library I uploaded to Cocoapods.
- Source folder contains the source code of the library
- GeometricLoaders folder contains a fully functional example of how GeometricLoaders works
Create podspec file
A Pod has a podspec file that defines the specifications of a Pod. In this example we have the following podspec:
Pod::Spec.new do |s|
s.name = "GeometricLoaders"
s.version = "1.1.0"
s.summary = "Fancy and beautiful loaders for you awesome apps!"
s.homepage = "https://github.com/pablogsIO/GeometricLoaders"
s.license = 'MIT'
s.author = "Pablo Garcia"
s.source = { :git => "https://github.com/pablogsIO/GeometricLoaders.git", :tag => s.version }
s.screenshots = ['https://raw.githubusercontent.com/pablogsIO/GeometricLoaders/master/Images/infinityloader.gif',
'https://raw.githubusercontent.com/pablogsIO/GeometricLoaders/master/Images/blinkingcirclesLoader.gif',
'https://raw.githubusercontent.com/pablogsIO/GeometricLoaders/master/Images/circleLoader.gif',
'https://raw.githubusercontent.com/pablogsIO/GeometricLoaders/master/Images/circleinmotionloader.gif',
'https://raw.githubusercontent.com/pablogsIO/GeometricLoaders/master/Images/orbitloader.gif',
'https://raw.githubusercontent.com/pablogsIO/GeometricLoaders/master/Images/waterwaves.gif']
s.platform = :ios, '10.0'
s.source_files = 'Source/*.swift'
s.frameworks = 'UIKit'
s.swift_version= '4.0'
s.requires_arc = true
s.social_media_url = 'https://twitter.com/_pablogs_'
end
- s.name: The name of the Pod.
- s.version: The version of the Pod. CocoaPods follows semantic versioning. The version have to be equals to GitHub's release
- s.summary: The description should be short, yet informative
- s.homepage: The URL of the homepage of the Pod
- s.license: The license of the Pod
- s.author: This is you!
- s.source_files: The location from where the library should be retrieved.
- s.screenshots: A list of URLs to images showcasing the Pod.
- s.platform: The platform on which this Pod is supported
- s.frameworks: A list of system frameworks that the user’s target needs to link against.
- s.swift_version: The version of Swift that the specification supports.
- s.requiresarc: requiresarc allows you to specify which source_files use ARC
- s.socialmediaurl: The URL for the social media contact of the Pod, CocoaPods web services can use this.
Here you can find more information about podspec file
Upload podspec and create a release
Once you have created podspec you have to create a release in Github.
Publishing your Pod
Well done!!! we are pretty close to the end.
Verifying your pod - Pod lib lint
Before publish your pod we should verify that everything is correct.
Open a terminal and in your project folder type
$> pod lib lint
If everything is ok you should get something like this...
-> GeometricLoaders (1.1.0)
GeometricLoaders passed validation.
Create a CocoaPods account
pod trunk register <Your Email>
For more information please visit Getting setup with trunk
Publish it!!!!
pod trunk push GeometricLoaders.podspec
And that's all folks!!!