Cartfile.private: How to specify private application dependencies using Carthage

In this lesson

In this lesson, I will show you how to use the optional Cartfile.private file to specify application dependencies that are private to your application.

Transcript

Tap on time to skip ahead

00:11

Hello everyone. In this lesson, we’re going to talk about a second Cartfile that you can add to your projects. To review, I created a MyNewApp folder, I created my own Cartfile and declared some dependencies and I used carthage update to resolve all my dependencies into a Checkout folder. If you recall, all these dependencies were either directly declared in my Cartfile or in the Cartfiles of some of my dependencies. We reviewed that lol-datadragon-content-provider was one of my libraries that had it’s own Cartfile. Let’s go look at that.

00:49

We’re at the lol-datadragon-content-provider repo. Let’s scroll down here. Remember that it declares its own Cartfile. In there, I declare three of its own dependencies which are then forced upon any other application or project that useslol-datadragon-content-provider as a dependency. What you may not have noticed is thatlol-datadragon-content-provider declares its own Cartfile.private. The format is exactly the same. It declares two other dependencies but those dependencies were not added to MyNewApp.

01:27

If we look back at the dependencies in MyNewApp, you’ll notice that there were two declared inlol-datadragon-content-provider, the Cartfile.private. It was called Quick and Nimble. Those are two dependencies that do not exist here. Why is that? I can tell you that, that is the purpose of the Cartfile.private and that’s what we’re going to talk about now.

01:53

In order to illustrate this, let’s create our own Cartfile.private. I’m going to use my text editor and create a new file. I’m going to use the origin syntax to declare two testing libraries that I want to use in MyNewApp. I know that i want to use the latest, 0.9.2 and I also want to use the Nimble library and that’s at 4.0.0. Let’s save that. The name is important. We’re going to call it Cartfile.private. We’re going to put it in the same folder as the Cartfile in MyNewApp. Now we have a private Cartfile and we’re going to use that to resolve some additional dependencies.

02:42

Let’s head over to my terminal window. We’re going to issue the carthage update command again. I’m going to –use-ssh to resolve those dependencies, which if I don’t specify this it will use the default HTTP protocol. Then I’m going to say –no-build, I just want to retrieve. If we run this, you’ll notice now, Quick and Nimble are the first two listed. Carthage will resolve dependencies out of both Cartfiles. These are the only two you can have. It will combine both the Cartfile and the Cartfile.private. I have now retrieved two additional dependencies using my Cartfile.private. The difference is, anything declared in Cartfile.private will not be forced upon anybody that’s referencing this library. That’s why my lol-datadragon that is here, it declared its own Cartfile.private and its dependencies declared on that file are not forced upon MyNewApp.

03:51

How do you figure out what to put in Cartfile and Cartfile.private? You’ll notice here in the Cartfile, these are dependencies of my application that are needed in order to run the application on the device. What you typically put in Cartfile.private are things like testing libraries or tools that aren’t required to build your main bundle. However, that’s why things like testing libraries and tool go into Cartfile.private and that’s why they’re not forced upon the parents that declare a dependency upon your own libraries.

04:30

That summarizes the use of Cartfile.private and you’ll be able to use this now in your own applications.