Last Updated: February 25, 2016
·
4.489K
· nathan chang

How to Create Private Pod

This document shows two samples which are made under cocoapods version 0.36.0.beta.1

We will go though
* How to use private pod created by teammates
* How to create private pod for existing universal library

<!-- more -->


Cocoapods

cocoapods is a very useful tool which manage frameworks/package for xcode.

People share lots of pods which can be found in the place as cocoapods search

By creating podspec, we can create our own pod to make module reuseable.
It's also possible to publish your pod by using pod trunk push POD_NAME.podspec.
Only one line pod 'POD_NAME' needed to be added in podfile, People can use your pod in their project.


What is Private Pod

Image that we are using a large core library which is implemented for company inner usage in various projects. For example, an universal fat library named testPrivatePod.a.

https://github.com/hsin919/testPrivatePod/

Everytime the CI release a new build testPrivatePod need to be cloned to local machine.

Private pod solve this problem.
cocoapods will check if there is any update for testPrivatePod.
The download will be triggered only if there is a new version.


How to Use Private pod Created By Teammates

  1. Add private pod to local. pod repo add testPrivatePod https://github.com/hsin919/testPrivatePod.git. You can double check if it's success under ~/.cocoapods/repos/testPrivatePod. <a href="https://www.flickr.com/photos/hsin919/16319653707" title="afteraddprivatepod by hsin chang, on Flickr">afteraddprivatepod</a> The output will become as below if we skip this step. <a href="https://www.flickr.com/photos/hsin919/16498838861" title="No spec by hsin chang, on Flickr">No spec</a>
  2. Add pod 'testPrivatePod', :path => '~/.cocoapods/repos/testPrivatePod' in podfile
  3. pod install(first time) or pod update We are good to go. <a href="https://www.flickr.com/photos/hsin919/16313133020" title="updateLib by hsin chang, on Flickr">updateLib</a>
  4. Now we are feel free to import <testPrivatePod.h>

Create Private pod for existing universal library

Assume we got the .h .a files on https://github.com/hsin919/testPrivatePod without the podspec file.

Create podspec

pod spec create testPrivatePod
pod lib lint

Edit .podspec until there is no complain by pod lib lint

<a href="https://www.flickr.com/photos/hsin919/16474576496" title="lib lint fail by hsin chang, on Flickr">lib lint fail</a>

Details of podspec

  • s.source = { :path => '*.{h,a}' } Specify the location from where the source should be retrieved.
  • s.source_files = "*.{h}" In the case of testPrivatePod only testPrivatePod.h is source code.
  • s.library = "testPrivatePod", s.preserve_paths = "libtestPrivatePod.a" and s.xcconfig = { 'LIBRARY_SEARCH_PATHS' => '~/.cocoapods/repos/testPrivatePod' }make pod project settings link to corresponding library after pod update

Update LIB

Finally, let's make a upgrade for our universal library.
1. Add + (void)printTest; in testPrivatePod.h & testPrivatePod.m
1. Rebuild the project and replace libtestPrivatePod.a in testPrivatePod
1. Increase version number for example s.version = "0.0.9" in testPrivatePod.podspec for example.
1. pod lib lint to double check podspec is correct
1. Commit changes for example.

The CI machine will update to version 0.0.9 in next autobuild.


Reference