Chris Mendez in Swift, Tools for Software Engineers, DevOps

Carthage cheat sheet

Carthage is fantastic for package management and 90% of the time I only need to execute carthage update but once in a while, I need to do something more specific so here are all those commands I can never seem to remember.


All You Need to Know

Configuring xCode

Go to Build Phases. Click "+" icon and choose Run Script. Create a Run Script and paste.

/usr/local/bin/carthage copy-frameworks

Examples


Downloading Libraries

Use Case #1 bootstrap

If I'm working with a another team and I need to evaluate their work, I won't use update, I'll use bootstrap instead. This ensures that I'm using the exact same dependecies that the other team is using.

carthage bootstrap --platform ios  

Use Case 2 update

I use this command all the time. Which says to update the app with the latest dependencies and create .framework builds for the iOS platform. Warning, this requires a lot of time.

carthage update --platform ios --no-use-binaries --verbose  

Bootstrap vs. Update

Method 1: bootstrap

bootstrap reads Cartfile.resolved, checks out and builds the dependencies at the versions listed.

carthage bootstrap  


Method 2: update

update reads Cartfile, runs a dependency resolver and checks out dependencies recursively –generally aiming for the newest versions that are compatible–  and rebuild the project's dependencies.

carthage update  

Build

This ensures that carthage doesn't skip over anything and builds the frameworks. You might want to use that with --no-use-binaries. This may take time.

carthage build --no-skip-current  

Using Parameters (Flags)

Build for a specific platform

Build for iPhone platform.

carthage [update|bootstrap] --platform ios  

Build for Mac desktop platform.

carthage [update|bootstrap] --platform macos  

Build for all platforms.

carthage [update|bootstrap] --platform all  


Download the dependencies as submodules

If you use this --flag, this makes the dependencies available as Git submodules. This allows you to make changes in the dependencies, and commit and push those changes upstream.

carthage [update|bootstrap] --use-submodules  


Don't be lazy and simply check out the binary frameworks

Use this flag to ensure all the workspace dependencies get checked out. Otherwise carthage will default to the binary framework releases.

carthage [update|bootstrap] --no-use-binaries  


Skip building the dependencies

This is a real time saver. You can download the dependencies but not build the .framework file. This will also skip the creation of a Carthage/build folder.

carthage [update|bootstrap] --no-build  


Only update this specific library

Instead of downloading and re-building all the dependencies, you can just specify which dependency to build.

carthage update [name of library]  

Troubleshooting

Verbose

Spell out everything that is happening.

carthage update --verbose  

Managing Cartfile

Create a Cartfile

Create a normal Cartfile

You will create a normal Cartfile 95% of the time.

touch Cartfile  


Create a private Cartfile

If you plan to install a test framework, this is the best way to do it. It allows you to use specific dependencies during development without having to build them for production.

touch Cartfile.private  

Paste this inside of Cartfile.private

github "Quick/Quick"  
github "Quick/Nimble"  


Dependency Origin vs. Version


Dependency Origin

Checkout a dependency from "some-branch-or-tag-or-commit"

github "duemunk/Async" "feature/Swift_3.0"  

Github Branch


Dependency Version

Compatible with version 0.9.2

github "jdg/MBProgressHUD" ~> 0.9.2  

At least version 2.3.1

github "ReactiveCocoa/ReactiveCocoa" >= 2.3.1  

Exactly version 0.4.1

github "jspahrsummers/libextobjc" == 0.4.1  

Build your own Carthage Framework