First question that came to my mind when I heard CocoaPods is, “What is that?”. In essence, it is a dependency manager for Swift and Objective-C projects. These dependencies are usually libraries that you can easily import into your Xcode project. If you are in the .NET world, this would be the same thing as a NuGet.
How to install on your Mac:
- Open Terminal
- Type in: sudo gem install cocoapods
- You will have to enter your password since the command sudo tells the terminal to run the following commands as another user; usually superuser by default
- Wait until it completes installing. You’ll get something like ‘18 gems installed‘ or such.
You may run into an issue where CocoaPods or some other part of the install requires a higher version of Ruby. In this instance, you can also install/update Ruby with the following command:
sudo gem install rails -v 4.2.6
You can choose whatever version you want. This also shows an error I received when I didn’t use the sudo command. You would then try to install CocoaPods again.
Now you may ask, how do I use CocoaPods to add dependencies into my project? Simple, create a PodFile in your project, then the commands needed to tell the program what to download. In this instance, I want to add the Bolts library to my XFinancial project (don’t mind the modified dates, I’m just trying to get my point across):
Then run the commands in the Terminal in the project directory: pod install
Then you should have installed it successfully:
You can go to https://cocoapods.org/ to search for libraries that you need.