Cocoapods - Easy but not easy
Someone told that Cocoapods is easy to use at both aspects: integrating open third-party into own project and publishing opensource library to community. However, for a newbie or even an experience developer, at the first time, it is not easy as a pie. This post is for them. Here we go!
Preparing git repository
Pushing source code
You should push source code to remote repository first.
1 2 3 git add . git commit -m "Initial commit" git push origin -u master
A tag should be created for the source code because we will need tag version to config podspec file later.
1 2 git tag -a 1.0.0 -m "Make v1.0.0" git push origin --tags
Change directory to project which you want to create a pod. In my case, I will go to
Next, create a podspec file:
Now, it’s time to config podspec file. See Pod specification to get further information. Just do like the example, it is OK. Note that
s.version should be set by a tag version like:
Thereafter, do a validation for podspec:
At the end of terminal screen,
pod-name.podspec passes validation appears let you know that your pod is OK to publish.
Otherwise, check again all fields in podspec file to ensure that all is accurate.
Next, go to do the last task, send a pull request (PR).
A note for s.source_files attribute in podspec file
It is to locate source files you want to publish. Thus, be sure that you provide the exact path for
s.source_files attribute. A legal path is a path from the root directory which contains
.git folder to destination file. For example, the below code show a path for
HUChartDemo project (but its repository name is HUChart, don’t be confused here, we need project’s root directory, not repository name).
Send a pull request to Specs
After that, we must send a pull request to
Specs to make the pod is visible. To do that, follow these steps:
- Fork Specs and clone it.
- Change directory (cd) to
- Assigns the original repo to a remote called “upstream”.
- Create our own Pod folder, ex.
1.0.0 is version number which we set for
s.version = "1.0.0" in podspec file.
- Copy .podspec file which we have already made some minutes ago to the version folder. In this case, version folder is
- Do git add this file and commit with a clear comment. After that, push it to forked Specs repository.
1 2 3 git add Specs/HUChart/1.0.0/*.podspec git commit -m "Added HUChart library to draw a semi circle chart." git push origin -u master
- Lastly, go to Specs pull page and press onto
New pull requestand fill all require fields to create a pull request. Thereafter, wait for Specs’ developers merge this request. Once they approve the request and merge it, we can use our lib as a Pod by Podfile.
It is so easy, isn’t it? But for me, the first time I created a pod, I wonder how pod work and how many necessary steps to make a pod successfully. Now, you have an own pod. Congratulations! Take time to share it as far as possible!
For Note: A source for setting up a private pod
blog comments powered by Disqus