一、使用HomeBrew安裝Carthage
避免安裝老版本的Carthage
,先update。
brew update
brew install carthage
二、使用
1、項目根目錄添加Cartfile文件
跟CocoaPods
添加Podfile
一樣,創建并編輯Cartfile
文件
vim Cartfile
Carthage
支持Github和git源,如:
github "ReactiveCocoa/ReactiveSwift" >= 1.0
github "Alamofire/Alamofire" ~> 1.0
github "Mantle/Mantle" == 1.0
執行命令,下載依賴庫并編譯為Framework
。
carthage update
執行完命令,自動生成Cartfile.resolved
文件,此時的目錄結構如下:
Cartfile
文件,手動添加項目需要的依賴庫及相應版本,需提交git/svn。Cartfile.resolved
文件,自動生成項目具體使用的依賴庫版本,需提交git/svn。Carthage
文件夾,自動保存依賴庫的源碼及編譯的Framework
,不需要提交git/svn(在git/svn的忽略文件添加“Carthage”即可)。
2、引入Framework
以下兩種方法最后的iOS
可以是iOS
、Mac
、tvOS
、watchOS
,分別對應不同平臺項目。
- 方法一:配置簡單,但工程中不能直觀的顯示所添加的依賴庫。
在Target -> Build Setting -> Framework Search Path 加入Framework
的搜索路徑即可。
$(SRCROOT)/Carthage/Build/iOS
- 方法二:配置稍麻煩,但所添加依賴庫都在
Framework
文件夾中。官網方法。
1、在General -> Linked Frameworks and Libraries -> + -> Add Other 添加上一步編譯的Framework
。
添加Framework
2、在Build Phases -> + -> New Run Script Phase,添加shell命令。
/usr/local/bin/carthage copy-frameworks
三、修改源碼
1、github項目源fork到自己賬號下
2、git clone自己fork的項目到本地目錄
git clone https://XXXX
3、修改源碼,git push到遠程倉庫
git add -A
git commit -m "XXXX"
git push origin master
4、修改cartfile相應類庫的賬號名稱,并指定分支名稱
github "https://XXXX" "master"
5、 執行carthage update
四、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 Carthage