CocoaPods are extensively wonderful but there is another option as well. Carthage is one of them for any cocoa application either iOS or Mac. It is tremendously easy to use compare to CocoaPods. It is developed by group of developers from Github. What I most like about it is – It is the first dependancy manager to work with Swift; and It is developed in Swift Language. We all know Apple has already started emphasis towards Swift so It will be better to get to know about Carthage.
1. Install Carthage in your computer
Download latest version from https://github.com/Carthage/Carthage/releases. Double-click Carthage.pkg to run the installer. Click Continue, select a location to install to, then click Continue again, and finally click Install.
You can also use Homebrew and install it simply by running brew update and brew install carthage.
Run carthage version command to ensure, it is perfectly installed on your system or not. It will display like 0.16.2.
2. Create Cartfile in your project directory
Run below commands :
cd ~/Path/Project
touch Cartfile
open -a Xcode Cartfile
github “Alamofire/Alamofire” == 2.0
github “SwiftyJSON/SwiftyJSON” ~> 2.3.0
3. Build Dependancy
Run below command to create required framework into your project directory.
carthage update –platform iOS
For more help on update command, use carthage help update for details.
4. Add Frameworks to your project
By default, Carthage will perform its checkouts and builds in a new directory named Carthage in the same location as your Cartfile. Open up this directory now by running:
open Carthage
You should see a Finder window pop up that contains two directories: Build and Checkouts. Take a moment to see what Carthage created for you.
Select the Project’s target, choose the General tab at the top, and scroll down to the Linked Frameworks and Libraries section at the bottom.
In the Carthage Finder window, navigate into Build\iOS. Now, drag both Alamofire.framework andSwiftyJSON.framework into the Linked Frameworks and Libraries section in Xcode.
Next, switch over to Build Phases and add a new Run Script build phase. Add the following command:
/usr/local/bin/carthage copy–frameworks
Click the + under Input Files and add an entry for each framework:
$(SRCROOT)/Carthage/Build/iOS/Alamofire.framework
$(SRCROOT)/Carthage/Build/iOS/SwiftyJSON.framework
Strictly speaking, this build phase isn’t required for your project to run. However, it’s a slick workaround for an App Store submission bug where apps with frameworks that contain binary images for the iOS simulator are automatically rejected.
Congratulations, you’ve learnt about the philosophy behind dependency management and behind Carthage itself, gained some experience using Carthage to add some dependencies to a project, and used those dependencies to make a useful app!
You also know how to update your dependencies for future releases.
If you want to learn more about Carthage, your first stop should be the Carthage README and the documentation on Build Artifacts.