A common, safe and flexible way to setup carthage for your project.
- Install Carthage
- Install Xcodeproj (Optional)
- Sample Project to follow (Optional)
First of all, you will need a working directyory for carthage. The most common place for this is your project root directory. However i would recommend to create a subdirectory and use it in order to keep the project structure clean. You can name as you want or for example Libraries, lib, libs.
There are multiple ways to integrate Carthage, but in this section, I will describe the way of using cehckout references
After you have chosen your working directory, follow these steps to integrate Carthage into it:
- Create a
Cartfile
and add some dependencies to it. - execute the following command
carthage update --no-build
- this will checkout all dependencies into aCarthage
directory and create aCartfile.resolved
file. - Ignore the
Carthage
directory from your git repository (you can copy the provided .gitignore file to your project root directory) - Add
Cartfile.resolved
to your git repository - Link the dependencies to your project (for more info look at Adding carthage dependency
If you need to have other dependencies, that are not managed by Carthage and keep the project structure clean, you can create a folder Unmanaged
to keep them there.
Sometimes it is easier to automate and protect few steps, just for convenience. If you want to do this, follow these steps:
- Add the provided scripts to your carthage working directory and commit them in your git repository
- resolve_dependencies.sh - use to resolve dependencies
- update_dependencies.sh - use to update dependencies
- check_dependencies.sh - used to check if dependencies needs to be updated
- configure_dependencies.rb - used to reduce depndency warnings noice by modifying their project file
- Add new
Run Script Phase
to your project and callcheck_dependencies.sh
from there - run
update_dependencies.sh
- build your project once more
- Ignore from your git repository the auto generated
perform_dependency_check
andCartfile.resolved.state
At the end you should end up with somethign like this:
Cartfile
- this is the Carthage configuration file, representing all dependenciesCartfile.resolved
- this is the Carthage configuration file, representing the current state of all dependencies. This file is autogenerated after you resolve your dependencies with carthage and should not be modified by hand.resolve_dependencies.sh
- this script resolves all dependencies to their current state.update_dependencies.sh
- this script updates all dependencies to latest version, according the Cartfile.check_dependencies.sh
- this script checks if dependencies needs to be updated.configure_dependencies.rb
- this script modifies all open source dependency project settings and perform configuration in order to reduce noise.Carthage
directory - this is the folder where all dependencies are stored upon resolution. This directory is automatically created and maintained by Carthage. This directory should not be commited into the repository and is explicitly ignored.Carthage
group - this is the group that wraps all dependency references. This group is only logical.Unmanaged
directory - this is the location where all unmanaged dependencies are physically and logically placed.
Carthage directory and Carthage group appears in the same location, but they do not represent the same thing. The group is intended to only wrap carthage managed references, where the folder contains the physical dependencies and is managed by Carthage itself.
- Add the dependency to the configuration file
- Run
update_dependencies.sh
script - Drag & Drop the project file (reference) to the Libraries folder (next to the other references)
- For every target:
- add it to Target Dependencies build phase
- add it to Link Binary With Libraries build phase
- if it is an embedded framework - add it to Embedded Binaries in the General tab
- Make sure that
- everytihng is working correctly
- you are not commiting the contents of the Carthage folder
- you are commiting the Carthage configuration files
- Instruct other team members to resolve their dependencies.
- Remove the dependency project reference from the project
- Remove the dependency entry from
Cartfile
- Remove the dependency entry from
Cartfile.resolved
or runupdate_dependencies.sh