Cocoapads 使用入门

Cocoapads 使用入门介绍

第一 安装

中国特色Cocoapads安装

在Mac的命令行中打入:

//更新
sudo gem update --system
//去除国外的ruby镜像 (有墙)
gem sources --remove https://rubygems.org/
//设置为 某宝的镜像
gem sources -a https://ruby.taobao.org/
//安装
sudo gem install cocoapods
pod setup

等一下下就安装好了

第二 使用

例如我要添加 AFNetworking,那么如下:

//cd 到一个有Xcode项目的地方
cd ~/Path/Developer/PodTest
//就像git一下 初始化一下
pod init
//打开podfile(最好用Xcode打开)
open -a Xcode Podfile

然后你就会看到 大概这个样子的东西

# Uncomment this line to define a global platform for your project
# platform :ios, "6.0"
 
target "PodTest" do
 
end

然后你把 # platform :ios, "6.0" 改动一下,例如我的

platform :ios, "8.0"

然后在 target 下面添加要的第三方,例如

pod 'AFNetworking', '2.2.1'

然后把podfile文件保存 关闭。

然后切换带命令行。

pod install

然后看到如下

Analyzing dependencies
Downloading dependencies
Installing AFNetworking (2.2.1)
Generating Pods project
Integrating client project
[!] From now on use `PodTest.xcworkspace`.

然后之后,只要打开那个workspace就可以用了。

Tip

如果停在Analyzing dependencies不动了,不要紧张,应该是cocoapods在更新自己的组件。如果你有耐心等等也可以,如果你和我一样没耐心就可以用下面方法停止其更新。

pod install --verbose --no-repo-update
pod update --verbose --no-repo-update

参考链接

link:http://www.raywenderlich.com/64546/introduction-to-cocoapods-2

你可能感兴趣的:(Cocoapads 使用入门)