Carthage使用(cocoapods的替代)

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
posted @ 2015-12-18 11:22  小书sky  阅读(3005)  评论(0编辑  收藏  举报