Carthage

Similarly to CocoaPods, Carthage is a tool which is used to manage external dependencies. But its idea is not to modify the project file and add all dependencies, neither is it here to support a central place where all dependencies are listed. Don't panic. Carthage does the heavy lifting for you. Namely, it downloads the source code and compiles a framework, which should be manually added to the project. 

Again, you have a file where all dependencies are described. Carthage uses that file to fetch all dependencies one by one and builds those. Then, it's up to you if you want to include the libraries in your project. When you update the dependency descriptor file, a new version will be fetched and built, but you have to manually update the linked framework. The update could be automated though; you just have to link the output file and once a new version is built, it will replace the old one.

The name of the descriptor file is  Cartfile. The structure is really simple compared to the Podfile file. There is a list of dependencies in the following format:

type web-address version

The type could be one of the three values such as github, git, or binary.

The address should be a corresponding web address or the name of the GitHub repository, where the resource could be found. For example, take a look at the following command:

github "Alamofire/Alamofire" ~> 4.5
git "https://path.to/the/git/repo.git" => 1.0

The final part of the definition could define a version rule or exact commit hash. You have to know the following common rules:

  • At least version x can be written as  >= x.0
  • Compatible with version x can be written as ~> x.0
  • Exactly version x.1 can be written as == x.1

If no version is specified, then any version is allowed and the best one which matches all other rules will be picked.

You may be wondering which dependency manager is better for your project. It depends on what you want to use. If all the dependencies are supported by CocoaPods, you can use it. For the rest, you can use Carthage. If you feel that you need to do a little manual work, then Carthage is a better match; the best solution is to try one. If you need something that's not supported from one dependency manager, you can always use both in the same project.

The third dependency manager which comes with Swift is Swift Package Manager.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.78.237