DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,673 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
himaratsu
himaratsu

Posted on

Use Carthage effectively

Carthage

Carthage is one of the most popular dependency management tool for iOS.

In my article, I introduce several convenient command to save your time.

Command

carthage update β€”platform ios

When executing carthage update, carthage create Cartfile.resolved from Cartfile you prepared. Then,
build frameworks.

In this command, you should specify platform you want to use frameworks in.

carthage update β€”platform ios

Carthage usually create multiple platforms frameworks(iOS, watchOS, tvOS, and macOS), but maybe not use these all.

carthage bootstrap β€”platform ios β€”cache-builds

When executing carthage bootstrap, carthage build frameworks from Cartfile.resolved file. Not from Cartfile.

carthage bootstrap β€”-platform iOS β€”cache-builds

β€”cache-builds means not rebuilding frameworks if you already had built frameworks in Carthage/Checkouts/
.

Fortunely, carthage automatically check if framework is built in same Swift version. If not, rebuild it.

Specify libraries

Cartfile is share between multi platforms. For example, iOS and watchOS.

Basically, command is here:
carthage bootstrap β€”platform iOS,watchOS

But it has problem. In many cases, watchOS doesn’t use all dependencies defined in Cartfile.

So, my recommend is:

carthage bootstrap β€”platform iOS
carthage bootstrap β€”platform watchos SWXMLHash

Separate command, and pass library name to build command for watchOS.

Use latest version of OSS

To shorten build time, you can use framework binary. It’s provided by Library Author, so you can use implicitly.

To use it, your project swift version needs to be same as swift version of that binary. If you use Swift 4.2, using library of version build in Swift 4.2.

Carthage skip checkout and build steps, so it is very efficiently.

Recap

Carthage is great tool, but build time is bottleneck. I introduce tips to resolve it.

Make hope this article helps you!

β€”-

*I'm studying English. If you notice English mistake, please tell me in the comments.

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.