1.使用homebrew安裝Carthage
brew intsall carthage
Ps:沒有安裝Homebrew的話,進入傳送門
Homebrew。順便提一句可以選擇簡體中文啊。

2.進入項目創建
vim Cartfile
Cartfile內容示例如下
>= 1.0
for “at least version 1.0” 1.0以上~> 1.0
for “compatible with version 1.0” 最好是1.0,== 1.0
for “exactly version 1.0” 必須是1.0- 什么也不寫,默認是最新版本
# 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"
為了簡單我只添加了一個 Ps:第一行為注釋
#Require version 2.0.0 github "Alamofire/Alamofire" ~> 2.0.0
3.終端運行
carthage update
運行carthage update的結果如下
*** Cloning Alamofire *** Checking out Alamofire at "2.0.2" *** xcodebuild output can be found in /var/folders/ps/vkznbcf51bd56ld8j4cby_5m0000gp/T/carthage-xcodebuild.kTo8yR.log *** Building scheme "Alamofire watchOS" in Alamofire.xcworkspace *** Building scheme "Alamofire OSX" in Alamofire.xcworkspace *** Building scheme "Alamofire iOS" in Alamofire.xcworkspace
文件目錄如下

其中文件Cartfile、Cartfile.resolved 和 Carthage文件夾是與Carthage被創建出來的,其他的項目自身帶的
4.打開 Carthage文件夾 進入Bulid。以iOS為例,進入iOS文件夾找到Alamofire.framework拖到項目中

或者在項目中選中Target -> Build Phases -> Link Library with Librarie點擊+號,然后點擊左下角的add Other.. 找到。framework添加就行

5.添加腳本
在 Build Phases -> +(左上角) -> New Run Script Phase
然后,點開Run Script 添加腳本
/usr/local/bin/carthage copy-frameworks
最后添加"Input Files”(以Alamofire為例)
$(SRCROOT)/Carthage/Build/iOS/Alamofire.framework
如下圖所示:


添加的腳本的作用
在App Store提交通用二進制觸發bug時這個腳本將運行,保證在歸檔時必要的bitcode相關文件被拷貝。
This script works around an App Store submission bug triggered by universal binaries and ensures that necessary bitcode-related files are copied when archiving.
另外需要注意Carthage 支持OS X的各個版本,但是對於iOS只支持iOS 8及其以上
only officially supports dynamic frameworks. Dynamic frameworks can be used on any version of OS X, but only on iOS 8 or later.
最后附上Carthage的github地址:
https://github.com/Carthage/Carthage