What is CocoaPods
CocoaPods is a dependency management tool for iOS projects. Generally, when developing iOS projects, you need to use CocoaPods to manage third-party components and components of private libraries.
CocoaPods installation
CocoaPods can be installed using RubyGems that comes with the Mac system.
Before installing CocoaPods, you generally need to update the Ruby image:
1 2 3 |
|
Open Terminal and enter the following command to install:
1 |
|
CocoaPods usage
Podfile
Pofile files detail the dependencies of targets in one or more projects.
An example of a podfile configuration:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Dependencies
Podfile describes the dependencies used in each user target
- pod is a way to declare specified dependencies
- podspec provides a simple API for creating podspec
- target allows you to limit dependencies in the project to only take effect in specified targets.
pod
Specify a dependency of the project. A dependency is declared by a pod name and optionally a version number.
1 2 3 4 5 6 |
|
In addition to specifying or not specifying the version number, you can do the following operations:
>0.1 Any version higher than 0.1
>=0.1 version 0.1 and any higher version
<0.1 any version below 0.1
<=0.1 version 0.1 and any lower version
~>0.1.2 Version 0.1.2 to version 0.2, excluding 0.2
Build Configurations
By default, dependencies are installed in all target build configurations. For scheduling or other reasons, dependencies can only be enabled in the specified target.
1 |
|
Subspec
When a Pod is declared to be installed, it will install all default subspecs defined in the podspec.
1 2 3 4 5 6 |
|
Using the files from a local path
If you want to use a local Pod developed by yourself, you can use the path option:
1 |
|
From a podspec in the root of a library repository (referencing the podspec in the root directory of the warehouse)
Use the master branch in the repository:
1 |
|
Use other branches in the repository:
1 |
|
Use a tag in the warehouse: (recommended)
1 |
|
Use a commit record in the repository:
1 |
|