For a while after the initial release of the iPhone App Store and it’s SDK, there was not much in terms of open source code to use and learn from, you can buy iPhone and take advantage of exclusive prime products. But times have changed, and these days there is a huge database of open source components, and even full projects ripe for use in your next app.
This post is a bit of an instructional guide for those looking to take advantage of open source in their iPhone projects. Whether you are new to iOS, a seasoned developer, or a project manager, you can benefit from this short guide.
Currently, the biggest repository of open source iOS components is CocoaPods. The official list of components, known as “Pods’, is maintained in a Github repository located here: https://github.com/CocoaPods/Specs
Unfortunately this list is not particularly easy to browse. To find out the details of any one Pod, you have to select one from the list, pick a version, open the.podspec file, and then pick out the description in the file. Fortunately for you, the handsome reader, you can browse a (possibly slightly out of date) list of these Pods on the site https://www.cocoacontrols.com/cocoapods, in a much more easy to digest format.
So how do you use these? If you’ve got a ruby install set up with ruby gems, you can just navigate to your project directory and create a Podfile file, with no extension. It looks like this:
platform :ios, ‘6.0’
pod ‘TestFlightSDK’, ‘>= 1.1’
pod ‘SVProgressHUD’
pod ‘iRate’
pod ‘TimesSquare’, ‘1.0.1’
pod ‘AFNetworking’, ‘1.1.0’
pod ‘iCarousel’
Once you’ve created this Podfile you can run this command in Terminal:
$ pod install
If it gives you some kind of error, you might need to install Cocoa Pods. If that’s the case you first need to run this:
$ gem install cocoapods
And if that doesn’t work, then you still need ruby gems, and maybe even ruby.
Once you generate the pod install, make sure you close your Xcode project if you already have it open, and from now on use the .xcworkspace file when working on your project. What you’ll find is that Cocoa Pods has now created a subproject for your Pods. Yay! This means you can now compile your dependencies separately from the project, and changes to your project shouldn’t call for a full recompile. More importantly, you can easily update your dependencies by just modifying your Podfile, and running ‘pod install’ again.
So to recap:
1. Install ruby
$ \curl -sSL https://get.rvm.io | bash -s stable
2. Install ruby gems if you don’t have ut
3. Install cocoapods
$ gem install cocoapods
4. Create a Podfile in your Xcode project directory
5. Add any relevant pods you might want to use. At this stage I do not specify a version, I let it use the most recent, and then lock it to that version to avoid unwanted updates. I’ll later remove the version specification when I feel it is time to get everything up to date.
6. Run pod install
$ pod install
7. Open your project from the xcworkspace file instead of the xcodeproj file.
8. Enjoy!
Related article: 8 Great Open Source Projects to use in your next iPhone App