A brief introduction to Carthage

Home page: Github.com/Carthage/Ca…
The author: Justin Spahr – Summers, etc
Version: 0.31
Goal: The easiest way to manage Cocoa third-party frameworks
Properties: Third-party framework management tools (similar to Cocoapods) Carthage manages third-party frameworks and dependencies for users, but does not automatically modify project files and generate configurations, giving users control over project structure and Settings.
The principle of Automatically program third-party frameworks as Dynamic Frameworks
limit Only iOS8+ is supported. It only supports frameworks, so it can’t be used to develop for systems prior to iOS8

Carthage installation and use

  • Download carthage. PKG installation package directly, install and run carthage. PKG download

  • If you are using XCode 7.0+, you can also use the following method to install

Install homebrew * 1

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Copy the code

2 to upgrade the brew

$ brew update
Copy the code

3 Use BREW for installation

$ brew install Carthage
Copy the code

4 Viewing the Version

   $ Carthage version
Copy the code

Use of Carthage

1 Go to the project folder first

 $ cdProject pathCopy the code

2 Create an empty Carthage file

$ touch Cartfile
Copy the code

3 Edit cartfile file, for example to install AFN framework

GitHub libraries can add the following to cartfile files, specifying GitHub keywords:

github  "AFNetworking/AFNetworking" 
Copy the code

Or fill in another git source and specify git keyword:

git "https://github.com/AFNetworking/AFNetworking.git"
Copy the code

4 Save and close the CARTfile file and use the cartfile to install the framework

$ Carthage update --platform iOS
Copy the code

Note: Multiple frameworks including iOS, OSX and TVOs will be compiled without additional parameters

Note 2: If this fails, open your project with Xcode, Product > Scheme > Manage Schemes in a new window, check Shared and click Close. Run the command again on the terminal

5 Open Carthage and view the generated file directory

$ open Carthage
Copy the code

  • Folder structure after executing the install dependencies command
There are three more files in the execution file

Cartfile Store a list of dependencies that need to be installed

Cartfile.resolved The dependency file is automatically generated and must be submitted to Git
Ensure that the submitted project can be enabled using exactly the same configuration and manner, keeping track of the dependency version number currently used by the project

Carthage # auto-generated Carthage directory (no need to commit to Git)
There are two folders in the Build Checkouts directory
# Build stores compiled files, including iOS/Mac/tvOS/watchOS framework
Git is a repository for git dependencies
Copy the code

6 Configuration Items

Open the project and go to Target -> Build Phases -> Link Library with Libraries to select the framework to import in the Carthage/Build directory

7 Add the compiled script

(This script file guarantees that the related files and dSYMs will be copied when submitting the archive.)

(1) Click Build Phases and click “+” -> New Run Script Phase

Add the /usr/local/bin/carthage copy-frameworks script

(3) add “Input Files” $(SRCROOT)/Carthage/Build/iOS/AFNetworking framework

Use third-party libraries in your projects

#import <AFNetworking/AFNetworking.h>

Other:

Uninstall Carthage: $brew uninstall Carthage

Update third party frames: Update multiple frames: Modify Cartfile file and re-execute $Carthage Update to update a certain frame: $Carthage Update specific frame name

carthage update  # Changed the Cartfile file and recompiled it
carthage update  Alamofire  # Update only the Alamofire framework
carthage update --platform ios  Build only the framework for iOS
carthage bootstrap    Recompile the dependencies from the local library
Copy the code

Advantages and disadvantages of Carthage

The advantages of Carthage

  1. Projects using CocoaPods are highly integrated, while Carthage is more flexible and emphasizes delegating tasks to Xcode and Git whenever possible.
  • CocoaPods automatically creates, updates, and consolidates workspace, dependencies, and Pod projects.

  • Carthage does not need to create and integrate the corresponding workspace and project, just rely on the packaged framework files.

  • In summary, CocoaPods’ approach is easier to use, while Carthage is more flexible and non-intrusive to the project.

  1. CocoaPods has a lot more functionality than Carthage and is therefore more complex, while CocoaPods has simple configuration and clean projects.

  2. CocoaPods has a central repository, whereas Carthage is decentralized. Without a central server, you avoid the failure of a central node, where Carthage only updates a specific library each time it configures and updates the environment.

  3. Carthage manages dependencies that only need to be compiled once, so when the project builds cleanly, there is no need to recompile dependencies, saving time

  4. Seamless integration with CocoaPods allows a project to have both CocoaPods and Carthage

The shortage of Carthage

  • Only iOS8 + is supported
  • It only supports frameworks, so it can’t be used to develop for systems prior to iOS 8
  • Third party frameworks and dependencies for supported Carthage installations are not as rich as CocoaPods
  • Unable to locate third-party library source in Xcode

Description of Carthage’s working process

  • 1. Create a Cartfile file in which you list the frameworks you want to use
  • 2. Run Carthage to get and compile the frames listed in Cartfile
  • 3. Configure the framework binaries into the project

About version designation

Carthage supports the following version specification methods:

>= 1.0 indicates minimum version 1.0. To > 1.0 indicates that version 1.0 is used but later than 2.0, such as 1.5, 1.9. == 1.0 indicates that version 1.0 must be used.Copy the code

“Some-branch-or-tag-or-commit” specifies that a Git object (whatever is allowed by Git rev-parse) is allowed to rely on any version if no version is required.

Versioning compatibility is determined by semantic versioning. This means that anything greater than or equal to version 1.5.1, but less than 2.0, will be considered “compatible” with 1.5.1.

Cartfile sample

# Require version 2.3.1 or later
github "ReactiveCocoa/ReactiveCocoa"> = 2.3.1# Require version 1.x
github "Mantle/Mantle"~ > 1.0# (greater than or equal to 1.0, less than 2.0)

# Require exactly version 0.4.1
github "jspahrsummers/libextobjc"= = 0.4.1Use the latest version
github "jspahrsummers/xcconfigs"

Use git branch
github "jspahrsummers/xcconfigs" "branch"

Use a project from GitHub Enterprise, in the "Development" branch
github "https://enterprise.local/ghe/desktop/git-error-translations"

Use a proprietary project from any Arbitrary Server, on the "development" branch
git "https://enterprise.local/desktop/git-error-translations2.git" "development"

Use a local project
git "file:///directory/to/project" "branch"
Copy the code

Git ignores files and folders that do not need to be committed to the repository

Modify the.gitignore file and add the ignore Carthage folder:

#Carthage
Carthage
Copy the code

Other orders of Carthage

 archive           Archives built frameworks into a zip that Carthage can use
 bootstrap         Check out and build the project's dependencies build Build the project's dependencies
 checkout          Check out the project's dependencies copy-frameworks In a Run Script build phase, copies each framework specified by a SCRIPT_INPUT_FILE environment variable into the built app bundle fetch Clones or fetches a Git repository ahead of time help Display general or command-specific help outdated Check for compatible updates to the project's dependencies
 update            Update and rebuild the project's dependencies version Display the current version of CarthageCopy the code