Guide Carthage to build Dependency in iOS app

Tram Ho

Introduce

  • In iOs application development, the use of external dependency is essential. This saves us time by taking advantage of components that others have built before. There are many ways to integrate dependency into your project.
  • The easiest way is to be able to directly download lib from github and drag the corresponding components into your project. However, such manual handling will take time, not professional. Moreover, these components may be related to other dependency components, making manual handling more difficult
  • The second way, we use the dependency management tool Coapods, Carthage .. to build dependency automatically. Thus, the management will be more effective and professional. This article will guide you step by step to build applications with Carthage.

Setting

There are many ways to install Carthage, Option 1: Download the .pkg file at https://github.com/Carthage/Carthage/releases and run the file to install.

Method 2: Install on the terminal using Homebrew.

Install Home brew:

Update to the latest version

After installing Homebrew we will install Carthage with the command

Build Project

Carthage uses the Cartfile file to list the libraries and versions for integration into the project.

Create Cart file

B1: cd to the project directory

B2: Create Cart file with command

B3: list the corresponding libraries into the cart file. For example

B4: Crtl + C to exit and save the file.

File Cart is defined according to OGDL: Ordered Graph Data Language. There are 3 components in declaring a Cart file.

– Dependency origin: To tell the source Carthage to fetch dependency.

  • For example: git, github ….

– Name dependency: Name of the denpendency to add to the project.

– Dependency Version: Version you want to add. Syntax

  • == 1.0: Use version 1.0
  • = 1.0: Versions greater than or equal to 1.0

  • ~> 1.5: Versions corresponding to 1.5.

Build Dependency

keyword –platform iOS to limit build for ios platform. Without this keyword, it will build for all MacOS and Watch

After the build is completed in the project, the Resolve file and the Carthage folder will be created as follows:

Open the Build / iOS folder. Drag the files Alamofire.framework and AlamofireImage.framework in BuildPharse / Link Binary with Libraries

  • Add Run Script

Add the following command to the link

and input file

Now the BuildPharse tab will look like this

  • Thus, we have completed the configuration and integrated the necessary dependencies into the project. Now we can import and use.

summary

Share the news now

Source : Viblo