Reading book is good practice, but it’s time to write several mini-tutorials on various problems, that I meet constantly. Today we will think about how to add Pods into your Xcode project.
CocaoPods (full name of “Pods”) is library manager for Xcode projects.
Lots of obj c and swift libraries can be installed using CocaoPods. It is very easy way of adding new library and it is definitely more accurate than copy-pasting source code of library. Lets see step by step how to add new Pod into your Xcode project.
Create your Xcode project (File -> New -> Project). I chose “Single View Application”.
For example I want to add ImagePicker library. In main page of this library’s GitHub page I found that the name of Pod is “ImagePicker”.
Check whether CocoaPods installed on your computer. Run command on terminal:
If you see instructions of using pod command (like on screenshot below), CocoaPods is installed.
Otherwise you need to install it using command:
gem install cocoapods
Maybe you will be forced to use “sudo”: sudo gem install cocoapods.
CocaPods installed. The next task is to prepare Podfile.
platform :ios, '10.0' use_frameworks! target 'InstallPodProject' do pod 'ImagePicker' end
Save this file as “Podfile” in root folder of your Xcode project. Replace “InstallPodProject” with the name of your project.
It’s time to install Pod. Type in terminal:
You should see message of successful installing like this:
.xcworkspace file will be generated.
Use this library in project. Before doing this remember that you need to open .xcworkspace file, not .xcodeproj. In Xcode check that in Pods you have desired library.
Build project (Cmd+R) to compile Pods. Import library in class you need and use this library.