Efficient Carthage
Carthage
Since iOS 8 Carthage has been helping to create frameworks with zero configuration (except for making the default scheme shared by a single click on the checkbox), manage dependencies on binary level without creating a workspace in Xcode (this has even more value now that ABI is finally coming and dynamic 3rd-party libraries can hopefully be shared too), and testing your frameworks by pointing not to GitHub but to a directory on a local file system.
Efficiency Level 1
Having 3rd-party dependencies in a project is all fine and dandy, but what do you do when you have plenty of projects using more or less the same set of 3rd-party frameworks? Well, by default you will have a copy of both source and binary of every dependency in every project you have. That’s not very efficient, is it?
So, it makes sense to create a shared Carthage directory for all your projects and create a symbolic link to it from every project that makes use of it. Let’s create a sharedCarthage
directory in our home directory by typing cd ~
and then mkdir Carthage
, then in project directory we can create a symbolic link by typing ln -s ~/Carthage ./Carthage
Efficiency Level 2
Many frameworks compile for multiple platforms (iOS, macOS, watchOS, tvOS) by default. What if we only work with iOS? We can spare build time by using --platform iOS
flag, i.e. building only for the platform we need. Moreover, we can use --cache-builds
flag when we do not want to rebuild unnecessarily. Sometimes, when we only need to check for a newer version or update the source, we can even use --no-build
flag.
Efficiency Level 3
It is getting a bit too verbose, isn’t it? Aliases are there to help! Let’s create file .aliases
in our home directory by typing cd ~
and then nano .aliases
and adding the following content to it -
alias cartlink="ln -s ~/Carthage ./Carthage"
alias cartboot="carthage bootstrap --no-build"
alias cartupdate="carthage update --no-build"
alias cartbuild="carthage build --platform iOS --cache-builds"
Now we can enable our aliases by typing source ~/.aliases
and then use any of them by typing its name, such as cartlink
.
Efficiency Level 4
How boring can it be to type source ~/.aliases
in every new terminal session? Right, it is time to adjust our bash profile! Let’s go to our home directory by typing cd ~
and then nano .bash_profile
and add the following line in the end -
source ~/.aliases
Done! Now we can use our aliases in every terminal session straight away.