CocoaPods is packaged as a Ruby gem. Since Ruby comes with new OS X installations, you can install CocoaPods simply by running the following commands in a terminal:
sudo gem install -n /usr/local/bin cocoapods # Install CocoaPods gem pod setup # Clones the CocoaPods specs repo to ~/.cocoapods
Podfile(only needs to be done once per project):
pod initfrom a terminal (in the root directory of your project)
Add the required dependency to the
Podfile. In the case below, we'll add AFNetworking:
# Uncomment the next line to define a global platform for your project # platform :ios, '9.0' target 'MyApp' do # Comment the next line if you're not using Swift and don't want to use dynamic frameworks use_frameworks! # Pods for MyApp # This pulls in the latest version of Alamofire >= 4.4 but less than 5.0. pod 'Alamofire', '~> 4.4' # Add additional dependencies pod 'OAuthSwift', '~> 1.1.0' pod 'OAuthSwiftAlamofire' end
MyApp.xcodeproject) if you have it open and open the workspace (
.xcworkspacefrom now on (which will contain your original project and the pods project).
CocoaPods version 0.36 was the first version to add support for Swift with the
As long as your app targets iOS8+, you can enable Swift support by adding the
use_frameworks! directive to your
platform :ios, '8.0' use_frameworks! # Instruct CocoaPods to use dynamic frameworks instead of static libraries for Pods ...
use_frameworks! directive, you can now consume Swift libraries using CocoaPods! After you've added
use_frameworks! to your
Podfile, you can directly import Swift libraries from your Swift code using the framework name (i.e.
use_frameworks! directive, you can also consume Objective-C libraries from your Swift code without the need of a bridging header anymore. You'll be able to directly import the framework (i.e.
Potential Issue: Unfortunately, all Objective-C Pods haven't been updated to work with the new dynamic frameworks behavior. You might come across certain Objective-C Pods that no longer build after adding the
use_frameworks! directive. In these cases you can either not use the
use_frameworks! directive (you'll now need to create a bridging header) or manually edit the offending Pod to help it find the headers (as done in the linked issue).
If you want to fully remove all traces of CocoaPods from your Xcode project, there's a tool that can do this for you. Run the following command to install the tool:
sudo gem install cocoapods-deintegrate
And then navigate to the directory that contains your project (the same directory that has the
Podfile files) and run the following command:
Note: This will remove all traces of CocoaPods from your project, but will leave 3 files hanging around on disk. If you want to fully remove all traces of CocoaPods, you'll also want to delete the following 3 files:
Carthage is an alternative dependency management system for Cocoa applications that has gained some traction recently. It prides itself on being a simple dependency manager that avoids the complexity of CocoaPods. To keep this simplicity, it doesn't automatically integrate the dependencies into your project (you must do that yourself). It also only supports iOS8 and above.