Nested dependencies with carthage


My notes on using nested dependencies with Carthage

Introduction

This article shows you how to organize your project so one dependency will use the next in the dependency graph. Instructions w/ gif how to use and make carthage projects can be found here: http://eon.codes/blog/2017/01/15/Carthage/

Carthage files:

Repo B - Cartfile

github "eonist/A" "master"

Repo C - Cartfile

github "eonist/B" "master"

Swift files:

Repo A - Demo.swift

public class Demo{
   public static func test(){
      Swift.print("\(self).test()")
   }
}

Repo B - Demo.swift

import A

public class Demo{
   public static func test(){
      Swift.print("\(self).test()")
      A.Demo.test()
   }
}

Repo C - Demo.swift

import A
import B

public class Demo{
   public static func test(){
      Swift.print("\(self).test()")
      B.Demo.test()
   }
}

Repo C - ViewController.swift

import UIKit
import C

class ViewController: UIViewController {
   override func viewDidLoad() {
      super.viewDidLoad()
      C.Demo.test()
   }
}

Output:

//C.Demo.test()
//B.Demo.test()
//A.Demo.test()

Birds-eye-view:

  • Getting in the habit of making projects with nested dependencies can greatly speed up build times, enable team members to contribute to your project more easily and enable you to share code in modules on github more easily.

  • You can update the source files of A or B and just push them to github and they will be included if you execute carthage update in the C project. No need to re-build etc in A and B. You can also target single/multiple deps. by calling: carthage update A B

img

Gotchas: