Cocoapods is a dependency manager for Swift and Objective C projects. As stated from the official site, it has over 28 thousand libraries and is used in over 1.7 million apps. It can make developers develop faster by using third party libraries. Cocoapods makes managing dependencies in your code easier. Adding and removing dependencies can be done by writing them in a file (called the podfile) and running it.
Version | Release Notes | Release Date |
---|---|---|
1.2.0 | https://github.com/CocoaPods/CocoaPods/blob/master/CHANGELOG.md#120-2017-01-28 | 2017-01-28 |
1.1.1 | https://github.com/CocoaPods/CocoaPods/blob/master/CHANGELOG.md#111-2016-10-20 | 2016-10-20 |
1.1.0 | https://github.com/CocoaPods/CocoaPods/blob/master/CHANGELOG.md#110-2016-10-19 | 2016-10-19 |
1.0.1 | https://github.com/CocoaPods/CocoaPods/blob/master/CHANGELOG.md#101-2016-06-02 | 2016-06-02 |
1.0.0 | https://github.com/CocoaPods/CocoaPods/blob/master/CHANGELOG.md#100-2016-05-10 | 2016-05-10 |
Lets start installing the popular library Alamofire to our Xcode project!
Lets first install CocoaPods by using the command:
[sudo] gem install cocoapods
Then let's create a new project in Xcode called Start! Navigate to the folder that contains the .xcodeproj
and create a new text file called podfile
!
Replace the podfile
with the following:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!
target 'start' do
pod 'Alamofire', '~> 4.3'
end
Use the cd
command to change to the directory containing the .xcodeproj
and issue the command pod install
. Alamofire is installed in the project 'start'!
Now, double-click the xcworkspace file (not .xcodeproj) and use Alamofire!
The dependencies for your projects are specified in a single text file called a Podfile. CocoaPods will resolve dependencies between libraries, fetch the resulting source code, then link it together in an Xcode workspace to build your project.
Create a podfile
# Next line contains target platform settings
platform :ios, '8.0'
# Use dynamic Frameworks
use_frameworks!
# Target name
target 'MyApp' do
# List of target dependencies
pod 'ObjectiveSugar', '~> 1.1'
pod 'ORStackView', '~> 3.0'
pod 'RxSwift', '~> 2.6'
end
Install dependencies. The process of dependencies installation is done by executing this command through terminal in the project directory:
pod install
Updating dependencies to new versions:
Updating specific pod
pod update RxSwift
Updating all pods
pod update
To update CocoaPods by simply installing the gem again
[sudo] gem install cocoapods
Or for a pre-release version
[sudo] gem install cocoapods --pre