ToolsiOS开发iOS开发

Carthage的使用

2017-02-23  本文已影响638人  AaronYin

Homebrew

打开终端,输入brew命令,如果发现没有brew命令,就需要先安装Homebrew

ichiledeiMac:octokit.objc-master aaron$ brew update
-bash: brew: command not found

Homebrew官网链接

安装brew只需要两行命令

首先打开终端,输入下面内容,回车

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

再输入下面的命令,就搞定了

brew install wget

ichiledeiMac:octokit.objc-master aaron$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
==> The following existing directories will be made group writable:
/usr/local/bin
==> The following existing directories will have their owner set to aaron:
/usr/local/bin
==> The following existing directories will have their group set to admin:
/usr/local/bin
==> The following new directories will be created:
/usr/local/Cellar
/usr/local/Homebrew
/usr/local/Frameworks
/usr/local/etc
/usr/local/include
/usr/local/lib
/usr/local/opt
/usr/local/sbin
/usr/local/share
/usr/local/share/zsh
/usr/local/share/zsh/site-functions
/usr/local/var

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/chmod u+rwx /usr/local/bin
Password:
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/bin
==> /usr/bin/sudo /usr/sbin/chown aaron /usr/local/bin
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/bin
==> /usr/bin/sudo /bin/mkdir -p /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var
==> /usr/bin/sudo /bin/chmod 755 /usr/local/share/zsh /usr/local/share/zsh/site-functions
==> /usr/bin/sudo /usr/sbin/chown aaron /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var
==> /usr/bin/sudo /bin/mkdir -p /Users/aaron/Library/Caches/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /Users/aaron/Library/Caches/Homebrew
==> /usr/bin/sudo /usr/sbin/chown aaron /Users/aaron/Library/Caches/Homebrew
==> /usr/bin/sudo /bin/mkdir -p /Library/Caches/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
==> /usr/bin/sudo /usr/sbin/chown aaron /Library/Caches/Homebrew
==> Downloading and installing Homebrew...
remote: Counting objects: 5129, done.
remote: Compressing objects: 100% (3218/3218), done.
remote: Total 5129 (delta 2816), reused 3379 (delta 1740), pack-reused 0
Receiving objects: 100% (5129/5129), 2.69 MiB | 1.29 MiB/s, done.
Resolving deltas: 100% (2816/2816), done.
From https://github.com/Homebrew/brew
 * [new branch]      master     -> origin/master
 * [new tag]         0.1        -> 0.1
 * [new tag]         0.2        -> 0.2
 * [new tag]         0.3        -> 0.3
 * [new tag]         0.4        -> 0.4
 * [new tag]         0.5        -> 0.5
 * [new tag]         0.6        -> 0.6
 * [new tag]         0.7        -> 0.7
 * [new tag]         0.7.1      -> 0.7.1
 * [new tag]         0.8        -> 0.8
 * [new tag]         0.8.1      -> 0.8.1
 * [new tag]         0.9        -> 0.9
 * [new tag]         0.9.1      -> 0.9.1
 * [new tag]         0.9.2      -> 0.9.2
 * [new tag]         0.9.3      -> 0.9.3
 * [new tag]         0.9.4      -> 0.9.4
 * [new tag]         0.9.5      -> 0.9.5
 * [new tag]         0.9.8      -> 0.9.8
 * [new tag]         0.9.9      -> 0.9.9
 * [new tag]         1.0.0      -> 1.0.0
 * [new tag]         1.0.1      -> 1.0.1
 * [new tag]         1.0.2      -> 1.0.2
 * [new tag]         1.0.3      -> 1.0.3
 * [new tag]         1.0.4      -> 1.0.4
 * [new tag]         1.0.5      -> 1.0.5
 * [new tag]         1.0.6      -> 1.0.6
 * [new tag]         1.0.7      -> 1.0.7
 * [new tag]         1.0.8      -> 1.0.8
 * [new tag]         1.0.9      -> 1.0.9
 * [new tag]         1.1.0      -> 1.1.0
 * [new tag]         1.1.1      -> 1.1.1
 * [new tag]         1.1.10     -> 1.1.10
 * [new tag]         1.1.2      -> 1.1.2
 * [new tag]         1.1.3      -> 1.1.3
 * [new tag]         1.1.4      -> 1.1.4
 * [new tag]         1.1.5      -> 1.1.5
 * [new tag]         1.1.6      -> 1.1.6
 * [new tag]         1.1.7      -> 1.1.7
 * [new tag]         1.1.8      -> 1.1.8
 * [new tag]         1.1.9      -> 1.1.9
HEAD is now at 76ca97b Merge pull request #2082 from reitermarkus/spec-os_mac_language
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Counting objects: 4159, done.
remote: Compressing objects: 100% (4012/4012), done.
remote: Total 4159 (delta 30), reused 453 (delta 10), pack-reused 0
Receiving objects: 100% (4159/4159), 3.32 MiB | 104.00 KiB/s, done.
Resolving deltas: 100% (30/30), done.
Tapped 4010 formulae (4,190 files, 10.4M)
==> Cleaning up /Library/Caches/Homebrew...
==> Migrating /Library/Caches/Homebrew to /Users/aaron/Library/Caches/Homebrew...
==> Deleting /Library/Caches/Homebrew...
Already up-to-date.
==> Installation successful!

==> Homebrew has enabled anonymous aggregate user behaviour analytics.
Read the analytics documentation (and how to opt-out) here:
  https://git.io/brew-analytics

==> Next steps:
- Run `brew help` to get started
- Further documentation: 
    https://git.io/brew-docs
ichiledeiMac:octokit.objc-master aaron$ bre
break  brew
ichiledeiMac:octokit.objc-master aaron$ brew install wget
==> Installing dependencies for wget: openssl
==> Installing wget dependency: openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2k.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring openssl-1.0.2k.sierra.bottle.tar.gz
==> Using the sandbox
==> Caveats
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
  /usr/local/etc/openssl/certs

and run
  /usr/local/opt/openssl/bin/c_rehash

This formula is keg-only, which means it was not symlinked into /usr/local.

Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/openssl/lib
    CPPFLAGS: -I/usr/local/opt/openssl/include

==> Summary
🍺  /usr/local/Cellar/openssl/1.0.2k: 1,696 files, 12M
==> Installing wget 
==> Downloading https://homebrew.bintray.com/bottles/wget-1.19.1.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring wget-1.19.1.sierra.bottle.tar.gz
🍺  /usr/local/Cellar/wget/1.19.1: 10 files, 1.6M

安装Carthage

安装Carthage,只需打开终端输入如下命令

$ brew update
$ brew install carthage

安装过程如下

ichiledeiMac:octokit.objc-master aaron$ brew update
Already up-to-date.
ichiledeiMac:octokit.objc-master aaron$ brew install carthage
==> Downloading https://homebrew.bintray.com/bottles/carthage-0.19.1.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring carthage-0.19.1.sierra.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completion has been installed to:
  /usr/local/share/zsh/site-functions
==> Summary
🍺  /usr/local/Cellar/carthage/0.19.1: 64 files, 22.1M

测试Carthage是否安装成功

ichiledeiMac:octokit.objc-master aaron$ carthage version
0.19.1

Carthage使用

1 用Xcode创建项目

创建项目,cd到工程目录

2 创建一个空的carthage文件

$ touch Cartfile

3 编辑Cartfile文件

编辑Cartfile文件,输入如下内容

github "AFNetworking/AFNetworking" ~> 3.0

版本含义

~> 3.0 表示使用版本3.0以上但是低于4.0的最新版本,如3.5, 3.9
== 3.0 表示使用3.0版本
>= 3.0表示使用3.0或更高的版本
如果你没有指明版本号,则会自动使用最新的版本

4 保存并关闭cart file文件,在终端执行命令

$ carthage update --platform iOS

安装过程如下

$ carthage update --platform iOS
*** Cloning AFNetworking
*** Downloading AFNetworking.framework binary at "3.1.0"
*** Checking out AFNetworking at "3.1.0"
*** xcodebuild output can be found in /var/folders/0y/2wpkp8ln7ql1zv8_gvvc74g00000gp/T/carthage-xcodebuild.p8Hx3q.log
*** Building scheme "AFNetworking iOS" in AFNetworking.xcworkspace

carthage会为你下载和编译所需要的第三方库,当命令执行完毕,在你的项目文件夹中会创建一个名为Carthage的文件夹

在 ~/Carthage/Build/iOS里会出现xxx.framework文件已经为你创建好了。

5 现在打开你的项目,点击project,选择target, 再选择上方的General,将需要的framework文件拖到 Linked frameworks and Binaries内

0DFAC4B7-878F-4C7C-8A9C-0BEC92F91E39.png

此时,你已经可以使用导入的第三方库了

上一篇 下一篇

猜你喜欢

热点阅读