I have checked several reference links and questions about how we can create the cocoa pods, tried:
Why?
Mainly because you want to do it, but then it has been proved to be the highly efficient approach when you know that this component you gonna uses again and again in most of your project. For example, a UITextview
that provides placeholder and character limit ¹, or a view that can be panned to the directions and area you want it to. Later we'll create while going through a course of this post.
What do you need?
How we'll proceed?
You'll see. Let's Do it!
Step 1: Create a pod project and write your code.
Tip: You can do that by typing
cd folder/path
of dragging your folder on the terminal after cd. Name it the same as your pod for future references. I will name it RPTInteractiveView. make sure to choose a unique name (it's a requirement) for your pod as well.
pod lib
this associated with lint
and create
is here to make your life easier.pod lib create
. You can check the console log for that here.
pod lib create RPTInteractiveView
What platform do you want to use?? [ iOS / macOS ]
>iOS
What language do you want to use?? [ Swift / ObjC ]
>Swift
Would you like to include a demo application with your library? [ Yes / No ]
>Yes
Which testing frameworks will you use? [ Quick / None ]
>None
Would you like to do view based testing? [ Yes / No ]
>No
Once the steps are done and processing completed, the project is created, if everything went right your project will be automatically get launched on Xcode, check for similar structure as:
Now you can write the code for the idea that will help the fellow developers. I prefer writing that in my example cod, Why? Because if you write code on pod project then each time when you try to see the reflection of the code written you will have to clean and re-run the code.
Pods->Development Pods->RPTInteractiveView.swift
You can also notice an R next to it, that is because I renamed it (here name doesn't matter much) earlier it used to be ReplaceMe.swift
and I did exactly what it requested for.pod 'RPTInteractiveView', : path => '/path/to/my/pod/RPTInteractiveView'
Step 2: Create a remote repository
RPTInteractiveView
). It doesn't necessarily have to be on GitHub but I am using that. Since we'll be making our pod available globally, keep the repo public.Step 3: The Metadata
Now that you have invested your time and efforts and love your pod, you are rather motivated for the next step, which we programmer often don't love much, updating the metadata. You gotta take care of all the files in Podspec Metadata folder the image above you can see that as the first group from the top, right below the project name.
s.version
must be the same s.summary
must be greater than the value given in s.description
s.homepage
should be the path of your repository (https://github.com/rptwsthi/RPTInteractiveView)s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author= { 'Your Name' => 'your@email.com' }
s.source
should look something like s.source = { :git => 'https://github.com/rptwsthi/RPTInteractiveView.git', :tag => s.version.to_s }
. As you see :tag => s.version.to_s this is why we need to keep our tag version the same as the project version, so it remains symmetric in all 3 places(project version, podspec version and tag of the commit that we want to publish with this version).pod lib
? Use it again on your terminal with lint
to verify if your podspec is ready.
$ pod lib lint
RPTInteractiveView passed validation.
, in color green³. README: This file is the difference between people using and not using your pod. This can be edited on Github you can do it locally. I prefer GitHub to do that interactively. Some stuff you should know while editing Readme:
License: License file is here to spare you from liability, and inform users about liberty they have. You must add your license information in this file and save it. I used MIT you can use whatever you want.
Step 4: Push to remote repository
Step 5: Let's make it available for fellow programmers.
pod trunk
.If not already registered you have to register with pod trunk and as stated here
pod trunk register your@emai.com 'Your Name' --description='machine name (e.g. MacBook Pro)'
You must click a link in an email Trunk sends you to verify the connection between your Trunk account and the current computer. You can list your sessions by running pod trunk me.
Trunk accounts do not have passwords, only per-computer session tokens.
Now as you have registered, in the terminal inside your project folder run:
pod trunk push RPTInteractiveView.podspec
As you have followed the steps perfectly you must have got a response that says. You can ee full console log here⁴