Create Private Pod

  1. 1. Cocoapods
  2. 2. What is Private Pod
  3. 3. How to Use Private pod Created By Teammates
  4. 4. Create Private pod for existing universal library
    1. 4.1. Create podspec
    2. 4.2. Details of podspec
    3. 4.3. Push podspec File
  5. 5. Update LIB
  6. 6. Reference

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

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.
    afteraddprivatepod
    The output will become as below if we skip this step.
    No spec
  2. Add pod 'testPrivatePod', :path => '~/.cocoapods/repos/testPrivatePod' in podfile
  3. pod install(first time) or pod update
    We are good to go.
    updateLib
  4. Now we are feel free to import <testPrivatePod.h>

If you need a local git system without push to any git repo.
Use pod repo add testPrivatePod /FILE_PATH/testPrivatePod/testPrivatePodRelease instead.

In this way the private pods will reference to local copy. Only if you do a local git commit, the CI will copy the new files to private pods path. So you can still feel free to change anything before doing git commit with podspec file


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

1
2
pod spec create testPrivatePod
pod lib lint

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

lib lint fail

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

Push podspec File

Push podspec to the place where teammates can access.
For example https://github.com/hsin919/testPrivatePod.git.
In this way, they can use your pods as private pod though pod repo add testPrivatePod https://github.com/hsin919/testPrivatePod.git


Update LIB

Finally, let’s make an upgrade for our universal library.

  1. Add + (void)printTest; in testPrivatePod.h & testPrivatePod.m
  2. Rebuild the project and replace libtestPrivatePod.a in testPrivatePod
  3. Increase version number for example s.version = "0.0.9" in testPrivatePod.podspec for example.
  4. pod lib lint to double check podspec is correct
  5. Commit changes for example.

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


Reference