Clicky

iOS Dev Nugget 126 Dependency Management for 3rd Party Code: Cocoapods

.

Need to run a code review on your codebase? Hire me

It's common to explicitly include open source code in iOS (or OS X) development. Cocoapods is a dependency manager that lets you track dependencies on 3rd party code, which in Cocoapods terminology, is known as pods, as well as update an Xcode workspace — which wraps around your Xcode project file – so all you need to do is the following:

  1. Install cocoapods if you haven't:

    sudo gem install cocoapods

  2. Create a Podfile in your Xcode project directory:

    pod init

  3. Update the Podfile to list which pod(s) and version you would like to use:

    source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.0' use_frameworks!

    pod 'AFNetworking', '~> 2.5' pod 'ORStackView', '~> 2.0' pod 'SwiftyJSON', '~> 2.1'

  4. Install the dependencies:

    pod install

  5. Open the .workspace file instead of .xcodeproj file.

  6. Import dependencies like this:

    import <AFNetworking/AFNetworking.h>

You then iterate through steps 3-6 during development and never use the .xcodeproj file again.

You can search for available pods at Cocoapods as well as for additional documentation.


Your feedback is valuable: Do you want more nuggets like this?   Yes   or   No

.

.

Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter

.

View archives of past issues