Carthage 是和 Cocoapods 类似的第三方库管理工具。和 Cocoapods 相比,Carthage 仅导入 framework 文件,做到更少的入侵性。但是Carthage 仅支持动态框架,只支持iOS 8
及以上版本或者任何的OS X
系统。
使用Homebrew安装Carthage
brew update
brew install carthage
注意 如果已经安装过Carthage的二进制版本,则应删除 /Library/Frameworks/CarthageKit.framework
向项目中添加frameworks【iOS】
-
在项目工程根目录中新建
Cartfile
文件。touch Cartfile
carthage update
命令获取并构建预编译的框架。- application targets -> General -> Link Frameworks and Libraries 从
Carthage/Build
文件夹中添加framework文件。 - 在
Build Phases
选项,单击“+”图标,选择New Run Script Phase
。创建一个运行脚本,您可以在其中指定shell(例如:/ bin / sh)
/usr/local/bin/carthage copy-frameworks
将frameworks目录添加到 “Input Files”, 例如:
$(SRCROOT)/Carthage/Build/iOS/Box.framework
$(SRCROOT)/Carthage/Build/iOS/Result.framework
$(SRCROOT)/Carthage/Build/iOS/ReactiveCocoa.framework
Cartfile
现在三个支持的起始点是GitHub repo,Git repo和通过https服务的二进制框架。
# Require version 2.3.1 or later
github "ReactiveCocoa/ReactiveCocoa" >= 2.3.1
# Require version 1.x
github "Mantle/Mantle" ~> 1.0 # (1.0 or later, but less than 2.0)
# Require exactly version 0.4.1
github "jspahrsummers/libextobjc" == 0.4.1
# Use the latest version
github "jspahrsummers/xcconfigs"
# Use the branch
github "jspahrsummers/xcconfigs" "branch"
# Use a project from GitHub Enterprise
github "https://enterprise.local/ghe/desktop/git-error-translations"
# Use a 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"
# A binary only framework
binary "https://my.domain.com/release/MyFramework.json" ~> 2.3
End~