今是昨非

今是昨非

日出江花红胜火,春来江水绿如蓝

Carthage usage

Background#

I have been using CocoaPods before. This time, when optimizing compilation time, I changed some library dependencies to Carthage. Here, I will record the usage of Carthage.

Usage#

Installation#

Install using brew, simple and convenient.

brew install carthage

Usage#

In the folder where the project is located, the folder where .xcodeproj is located, create a Cartfile.

touch Cartfile

Then open Cartfile.

open Cartfile -a Xcode

Add the third-party libraries to be dependent on, pay attention to specifying the version of the dependency, the syntax for specifying the version and the range is as follows:

github "krzyzanowskim/CryptoSwift" ~> 1.4.0
github "evgenyneu/keychain-swift" ~> 19.0
github "ibireme/YYKit"
github "ReactiveX/RxSwift" "6.5.0"
github "onevcat/Kingfisher" "version6-xcode13"
github "alibaba/HandyJSON" ~> 5.0.2
github "https://github.com/antitypical/Result.git"
github "pkluz/PKHUD" ~> 5.0
github "Moya/Moya" ~> 15.0

Note that in Carthage, some SDKs compile all platforms. You can import them into the project according to actual needs, such as RxSwift and Moya.

The last step is to install, pay attention to the differences in the following methods:

# Compiles all platforms, such as tvOS, iOS, macOS, etc.
carthage update --use-xcframeworks

# Only compile iOS libraries
Carthage update --platform ios --use-xcframeworks

# Only compile iOS libraries, and if the compiled cache exists, do not compile repeatedly
Carthage update --platform ios --use-xcframeworks --cache-builds

# Refer to https://stackoverflow.com/questions/41442601/whats-the-purpose-of-no-use-binaries-in-carthage
carthage build --platform ios --use-xcframeworks --no-use-binaries

After compilation, import the generated xcframework into the project. In the Frameworks, Libraries, and Embedded Content section under the project's General settings, you need to switch the checkbox to Embed & Sign, as shown below:

Diagram

If you are using SwiftLint, you may encounter errors after compilation. Add Carthage to the exclusion list in .swiftlint.yml, as shown below:

excluded:
  - Pods
  - Carthage

Finally, if Carthage projects are committed and other people pull this project, they need to run the following command to synchronize Carthage frameworks:

carthage bootstrap

References#

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.