Swfit依赖管理工具Carthage的安装与使用

一、使用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可以是iOSMactvOSwatchOS,分别对应不同平台项目。

  • 方法一:配置简单,但工程中不能直观的显示所添加的依赖库。
    在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

添加shell命令

三、修改源码

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Carthage v0.26.2(原文链接) Carthage的目标是用最简单的方式来管理Cocoa第三方框架。 ...
    iOSLee阅读 9,032评论 0 7
  • 文档地址https://github.com/Carthage/Carthage release v0.20.0...
    指尖弹灰阅读 10,054评论 2 4
  • 一. 简介 我之前用过 CocoaPods,很大一部分原因就是因为麻烦,仅个人感觉,需要牵扯 XCode 项目文...
    coderTian阅读 3,971评论 3 2
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,323评论 19 139
  • 1. brew 安装Carthage之前需要安装brew,进入官网(https://brew.sh/index_z...
    濤子阅读 6,208评论 0 1