When you develop an app for iOS (iPhone or iPad), you often need to use third-party libraries (if something you need already exists, you don’t need to develop it again!).
If you have a quite big project, you can end up with lots of libraries used by your code; that would lead to the following problems:
- Difficulties maintaining all the libraries up to date
- Difficulties maintaining the dependencies between all the libraries
- Some libraries are quite complex to integrate (e.g. AddThis)
In order to solve all those problems and make your life a lot easier, here comes CocoaPods!
CocoaPods is a simple tool written in Ruby that will help you maintain easily all your third-party libraries in your projects by using a simple config file. To use it, simply follow those steps:
- Open a Terminal window on your Mac
- Install CocoaPods by entering the following commands:
$ [sudo] gem install cocoapods $ pod setup
- Navigate to the folder of your Objective-C project (where your App.xcodeproj file is)
- Create a file named “Podfile” and add all the libraries you need (here is the Podfile for Scrmbl)
1 2 3 4 5 6 7
$ vi Podfile platform :ios, '6.0' #deployment target of your iOS project pod 'TSMessages' pod 'CMPopTipView' pod 'RevMob' pod 'UI7Kit' pod 'iRate'
- Install the libraries you chose
$ pod install
- Now, when you want to open your project in XCode, always open the file App.xcworkspace
When you compile and run your project (simulator or device), XCode will create a static library for all your Pods (the libraries you chose to install via CocoaPods) and add it to your project. So you don’t have to worry anymore about copying the source files of the libraries. Everything is managed by CocoaPods!
If you want to update your libraries, simply type the following:
$ pod update
Happy coding! 🙂