Cocoapods Overview - library dependency manager for iOS

Prajwal21 148 views 15 slides Sep 25, 2017
Slide 1
Slide 1 of 15
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15

About This Presentation

Cocoapods overview
- Learn how to install cocoapods
- pod init, install, update
- pod try
- pod create & publishing pods to cocoapod
- creating private pods


Slide Content

COCOAPODS
What is cocoapods?
CocoaPods is the dependency manager for Cocoa projects written in
either Swift or Objective C. It has thousands of libraries and can
help you scale your projects elegantly.
Presented By Prajwal S
Presentation © by Prajwal S, cosmostack.com

DISCOVERY
CocoaPods was created by Eloy Durán on August 12, 2011.

Taking inspiration from Bundler and RubyGems, CocoaPods was
designed to resolve a list of dependencies, download the required sources,
and configure the existing project in such a way to be able to use them. 

Presentation © by Prajwal S, cosmostack.com

USING COCOAPODS
CocoaPods is easy to get started with both as a consumer and a library
author. It should only take a few minutes to get set up.

Installing CocoaPods:
CocoaPods is installed through RubyGems, the Ruby package manager, which
comes with a standard OS X install.
To install, open Terminal.app and enter the following command:
$ sudo gem install cocoapods 

Now you should have the pod command available in the terminal.
Presentation © by Prajwal S, cosmostack.com

MANAGING DEPENDENCIES
A dependency manager resolves a list of software requirements into a list of
specific tags to download and integrate into a project.
Declaring requirements in such a way allows for project setup to be automated, which
is general best practice for software development practice, no matter what the
language. 


Even if you don’t include third-party libraries, CocoaPods is still an invaluable
tool for managing code dependencies across projects.

Podfile
A Podfile is where the dependencies of a project are listed. It is equivalent to Gemfile
for Ruby projects using Bundler, or package.json for JavaScript projects using npm.
To create a Podfile, cd into the directory of your .xcodeproj file and enter the command:
$ pod init
Presentation © by Prajwal S, cosmostack.com

PODFILE STRUCTURE
The Sample Podfile looks like, with specifying all dependency library for the project
Once all of the dependencies have been specified, they can be installed with:
$ pod install

When this is run, CocoaPods will recursively analyze the dependencies of each project,
resolving them into a dependency graph, and serializing into a Podfile.lock file.
Presentation © by Prajwal S, cosmostack.com

SEMANTIC VERSIONING
Besides no version, or a specific one, it is also possible to use logical operators:
'> 0.1' Any version higher than 0.1
'>= 0.1' Version 0.1 and any higher version
'< 0.1' Any version lower than 0.1
'<= 0.1' Version 0.1 and any lower version

In addition to the logic operators CocoaPods has an optimistic operator ~>:
'~> 0.1.2' Version 0.1.2 and the versions up to 0.2, not including 0.2 and
higher
'~> 0.1' Version 0.1 and the versions up to 1.0, not including 1.0 and higher
'~> 0' Version 0 and higher, this is basically the same as not having it.

Presentation © by Prajwal S, cosmostack.com

FUNCTIONING OF PODS
CocoaPods will create a new Xcode project that creates static library
targets for each dependency, and then links them all together into a
libPods.a target. This static library becomes a dependency for your
original application target. An xcworkspace file is created, and should be
used from that point onward. This allows the original xcodeproj file to
remain unchanged.


Maintaining Pods:
Subsequent invocations of pod install will add new pods or remove old
pods according to the locked dependency graph. To update the individual
dependencies of a project to the latest version, do the following:
$ pod update
Presentation © by Prajwal S, cosmostack.com

< Dependant frameworks for libraries
< Pods framework built with all the below libraries compiled
by Pods project linked to our working project.
< Library sources added by cocoapod
< Frameworks built by cocoapods
from dependecy library source added
Presentation © by Prajwal S, cosmostack.com

CREATING A COCOAPOD
Specification:

A .podspec file is the atomic unit of a CocoaPods dependency. It specifies the name, version, license, and
source files for a library, along with other metadata.
Once published to the public specs database, anyone could add it to their
project, specifying their Podfile thusly.

Sample specs:

https://guides.cocoapods.org/making/specs-and-specs-repo.html
NSAlertUtils.podspec
Ruby code:
$ pod spec create
Presentation © by Prajwal S, cosmostack.com

PUBLISHING A COCOAPOD
To get started, you must first register your machine with the Trunk service. This
is easy enough, just specify your email address along with your name.

$ pod trunk register [email protected] “Prajwal S"


Run pod spec lint. This is used to validate specifications. Your podspec should
pass without any errors or warnings.
$ pod spec lint
Now, all it takes to publish your code to CocoaPods is a single command. The
same command works for creating a new library or adding a new version to an
existing one:
$ pod trunk push NAME.podspec
Presentation © by Prajwal S, cosmostack.com

SEARCHING COCOAPODS
Presentation © by Prajwal S, cosmostack.com

PRIVATE PODS
1. Create a Private Spec Repo
To work with your collection of private pods, it is suggest to create own Spec repo. This
should be in a location that is accessible to all who will use the repo.

2. Add your Private Repo to your CocoaPods installation
$ pod repo add REPO_NAME SOURCE_URL
Note: If you plan on creating pods locally, you should have push access to SOURCE_URL
$ cd ~/.cocoapods/repos/REPO_NAME
$ pod repo lint
3. Add your Podspec to your repo
$ pod repo push REPO_NAME SPEC_NAME.podspec

This will run pod spec lint, and take care of all the little details for setting up the
spec in your private repo.
Presentation © by Prajwal S, cosmostack.com

$ pod intall Thankyou
Any Questions?
Some short videos to understand more about cocoapods:
https://www.youtube.com/playlist?list=PLqyi3cdI8X36fjtSmlZRVnvghk9mlbqjC
Presentation © by Prajwal S, cosmostack.com

ONE MORE THING…….
$ pod try Hero
Pod try:
CocoaPods plugin which allows to quickly try the demo project of a Pod.
Presentation © by Prajwal S, cosmostack.com

THANK YOU