安裝
透過 homebrew 安裝即可
$ brew update
$ brew install carthage
基本指令
可以直接輸入 carthage
執行,看基本的指令集
$ carthage
就會印出這樣的資訊
Available commands:
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 Carthage
Cartfile
就像 Podfile 一樣,這個工具的設定檔就是 Cartfile
先在終端機裡面進到 Xcode 專案的目錄之後,
vim Cartfile
來透過 vim 開始編輯 Cartfile
內容就相對簡單多了,先試試看加入 Alamofire
Cartfile
github "Alamofire/Alamofire" ~> 4.4
接著儲存退出 - :wq
並在 command line 執行
$ carthage update
就可以生成可以拖曳進 Xcode 的 framework 檔。
如果只要 build for iOS ,可以加上 flag 加上限制
$ carthage update --platform iOS
接著就會陸續印出以下的資訊:
*** Fetching Alamofire
*** Checking out Alamofire at "4.4.0"
*** xcodebuild output can be found in /var/folders/xr/_qcc9bwd2016f0ygl69qrvp80000gn/T/carthage-xcodebuild.7tbiKU.log
*** Building scheme "Alamofire iOS" in Alamofire.xcworkspace
拉入專案
這時候在專案的這個路徑
Carthage/Build/iOS/
下,就可以看到一個叫做 Alamofire.framework
的檔案,接著就可以把這個 framework 檔案拖曳進 Xcode 裡面的這個地方:
Target (pick one) > General > Linked Frameworks and Binaries
接著在隨意的 Swift 檔案裡面,試試看能不能透過自動完成 Alamofire
的方式載入
import Alamofire
就算大功告成了。