Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Private Pod Support Using CocoaPods in iOS

DZone's Guide to

Private Pod Support Using CocoaPods in iOS

Learn how to manage your mobile development projects by using a dependency manager tool that allows you to manage external libraries.

· Mobile Zone
Free Resource

Download this comprehensive Mobile Testing Reference Guide to help prioritize which mobile devices and OSs to test against, brought to you in partnership with Sauce Labs.

You might have read our recent blog on SDUI framework that introduced the concept of UI presentation made easier by eliminating the need for frequent updates to an application by the end user. It is built and deployed with just “one code base logic” and is applicable for each of the UI releases while eliminating the need for frequent updates of the Apps.

The framework can be of used in other iOS projects; hence it requires a lot of effort in manually installing and building it. Therefore, to overcome this challenge the team explored various options and found a more centralized solution, ‘CocoaPods’ - a dependency manager tool that provides a standard format for managing the external libraries. It has over 27 thousand libraries and is used in over 1.6 million apps and can help scale any project elegantly. It focuses on the source-based distribution of third party code and automatic integration into Xcode projects.

Getting Started

The dependencies for projects are specified in a single text file called a Podfile. CocoaPods will resolve the dependencies between libraries, fetch the resulting source code, and then link it together in the XCode workspace to build your project.

Image title

Follow the Below Steps to Add Private Pod in Your Ios Project:

By default, CocoaPods uses a public specification repository (https://github.com/CocoaPods/Specs). If you want to make your pod private then you have to create a private repository with the same structure and upload your pod specification file to the private repository.

Installation

1. CocoaPods is built with Ruby and it will be installable with the default Ruby available on Mac OS. Using the default Ruby install will require you to use “sudo” when installing gems.

2. Follow the below command to install Cocopods in your system:

$ sudo gem install cocoapods


Create a pod specification file (.podspec file).Create and Use Cocoapods in Your Ios Project

  • The specification file contains detailed information about the repository. When you execute pod install or pod update commands, CocoaPods will look into the specification file and clone the repository.

Follow the Below Steps:

1.Create a specification for your pod using the following command:

$podspec create <your_pod_name>

Example: pod spec create AppUtils

2.Edit the AppUtils.podspec

  • Name – name of the pod.
  • Version – the current version for the specification. Your repo must contain a tag for the version number. i.e. 1.0,1.2 etc.
  • Summary – a short summary of project.
  • Description – detailed description of the project.
  • Homepage – homepage of the project.
  • License – license for the project, i.e – MIT,BSD.
  • Author – author of the repo.
  • Platform – OS and version used in the repo, i.e. iOS 9.0.
  • Source – source URL of the repo.
  • source_files – files to be included in the pod.
  • exclude_files – files not to be included in the pod.
  • Dependency – any third party dependency for the pod project.

3.Now verify the pod spec file by using the following command:

$ pod spec lint AppUtils.podspec

Image title

  • Solve any error or warning that may occur while validating .podspec file

4.Now upload the specification file to your specification repository.

CocoaPod is using a public specification repository for the public pod. If you want to create a private pod then you have to create your own private specification repo that will store.podspec files.

Image title

Each version has its own specification file. Your specification repository can have more than one specification.Image title

5.Specifying a private pod in Podfile.

If you are using a private pod then you have to tell CocoaPod, where the specification repository is located by specifying the source at top of the Podfile:

Source “<path of your privatespecification git repo> "
pod 'AppUtils', '~> 1.0'


If you don’t want to create a private specification repository then create the same specification structure in your project and specify the repository URL as the source in the Podfile.

Image title

Benefits

CocoaPods are widely used for third party dependency integration. Below are few benefits of using CocoaPod over manually managing Dependencies in your project.

  • Managing dependencies in your code is simplified by downloading all of them when you run the pod install/update command.
  • Manually added dependency may not be easy for another coder to locate it. Pods ensure that one can easily go through the pod scheme or a Podfile to understand all the dependencies used in the project.
  • The task of replacing a library with a new version is simplified with CocoaPods automatically by using only one command instead of manually deleting old files and adding new ones.

Conclusion

Private pods make managing your project much simpler. It saves a lot of effort and time when dealing with dependencies in your project. Also, we can use this pod privately for internal access.

Analysts agree that a mix of emulators/simulators and real devices are necessary to optimize your mobile app testing - learn more in this white paper, brought to you in partnership with Sauce Labs.

Topics:
ios ,cocoapods ,mobile ,github ,libraries

Published at DZone with permission of Kirit vaghela. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}