CocoaPods是一个负责管理iOS项目中第三方开源代码的工具。CocoaPods项目的源码在Github上管理。该项目开始于2011年8月 12日,经过一年多的发展,现在已经超过1000次提交,并且持续保持活跃更新。开发iOS项目不可避免地要使用第三方开源库,CocoaPods的出现 使得我们可以节省设置和更新第三方开源库的时间。

安装

在安装之前,运行以下命令

  1. gem update --system

可以升级系统当前的ruby版本

安装方式异常简单, Mac下都自带ruby,通过终端(Terminal)使用ruby的gem命令即可下载安装:

  1. $ gem install cocoapods
  2. $ pod setup
  1. gem install cocoapods

命令也可以自动升级当前cocoapods版本

一旦安装完毕,通过运行

  1. pod setup

命令来设置CocoaPods

Once installed, setup CocoaPods by running the pod setup command.
During the setup process, the CocoaPods environment is formed and a
.cocoapods directory is created in your home folder. This hidden folder
contains all the available pod specifications or pod specs.

A dependency declaration has a lot more configuration options, which
can be set in the Podfile. If you want to work with the bleeding edge
version of a library, for example, you can replace a pod’s version
number with :head as shown below. You can even tell CocoaPods what
source to use by specifying the git repository or referring CocoaPods to
a local copy of the library. These are more advanced features of
CocoaPods.

  1. pod 'AFNetworking', :head
  2. pod 'SVProgressHUD', :git => 'https://github.com/samvermette/SVProgressHUD'
  3. pod 'ViewDeck', :local => '~/Development/Library/ViewDeck'
  4. pod 'DTCoreText', :git => 'https://github.com/Cocoanetics/DTCoreText.git'

With our list of dependencies specified, it is time to continue the
setup process. Update the Podfile as shown below and run pod install in
the Terminal. Make sure to run this command in the root of your Xcode
project where you also created the project’s Podfile.

  1. platform :ios, '6.0'
  2. pod 'ViewDeck', '~> 2.2.2'
  3. pod 'AFNetworking', '~> 1.1.0'
  4. pod 'SVProgressHUD', '~> 0.9.0'
  5. pod 'HockeySDK', '~> 3.0.0'
  6. pod install

使用:

Open Terminal, and navigate to the folder where your project is. Type the following:

  1. touch Podfile
  2. open -e Podfile

TextEdit should open up showing an empty file. You just created the
pod file and opened it! Ready to add some content to the empty pod file?

Copy and paste the following lines into the TextEdit window:

  1. platform :ios
  2. pod 'AFNetworking', '0.9.1'

Now, save the file and close TextEdit, going back to terminal. Ready to configure your project?

Issue the following command via Terminal:

  1. pod install

You should see output similar to the following:

  1. Updating spec repo `master'
  2. Installing AFNetworking (0.9.1)
  3. Generating support files

It might also tell you something like this:

  1. [!] From now on use `CocoaPodsExample.xcworkspace'

If you type ls now (or browse the project folder using Finder),
you’ll see that CocoaPods created a Pods folder – where it stores all
dependencies – and CocoaPodsExample.xcworkspace.

  1. VERY IMPORTANT!
  2. From now on, as the command-line warning mentioned, you must always open the workspace (CocoaPodsExample.xcworkspace) and not the project!

现在,你的所有第三方库都已经下载完成并且设置好了编译参数和依赖,你只需要记住如下2点即可:

使用CocoaPods生成的 .xcworkspace 文件来打开工程,而不是以前的 .xcodeproj 文件。

每次更改了Podfile文件,你需要重新执行一次pod install命令

安装DTCoreText一定要注意Other Linker Flags的属性值

-all_load和-ObjC要满足

CocoaPods 安装使用的更多相关文章

  1. 最新的 cocoaPods 安装方法

    经过努力终于发现了最新的 解决cocoaPods安装的办法: taobao Gems 源已停止维护,现由 ruby-china 提供镜像服务 第一步:安装rvm, 不管需不需要升级ruby,rvm可以 ...

  2. cocoapods安装

    什么是cocoapods CocoaPods是一个用来帮助我们管理第三方依赖库的工具.它可以解决库与库之间的依赖关系,下载库的源代码,同时通过创建一个Xcode的workspace来将这些第三方库和我 ...

  3. iOS 之 Cocoapods安装

    进入正题前,先来点前奏:了解cocoapods是某天看一个博客,那时才明白原来写项目不用一个个将三方库拷进项目里啊,惊讶的我是一塌糊涂的啊...(原谅我那时还没进入过正规的IT公司....好多你们自然 ...

  4. mac 10.11.6,Xcode8下,ruby2.3安装,Cocoapods安装~

    适用环境 mac: 10.11.6 Xcode:8.1 命令执行步骤(安装ruby2.3前准备工作) 查看ruby更新源 gem sources  -L 删除默认官方或者淘宝,新增 https://g ...

  5. Mac 下安装ruby,以及CocoaPods安装以及使用网摘

    ruby安装网址:https://ruby-china.org/wiki/install_ruby_guide CocoaPods安装和使用教程地址:http://code4app.com/artic ...

  6. cocoapods安装以及使用,安装过程中ruby版本过低

    cocoapods安装以及使用,安装过程中ruby版本过低 字数473 阅读103 评论1 喜欢2 1.打开终端 2.移除现有 Ruby 默认源 $ gem sources --remove http ...

  7. 2016最新CocoaPods安装和错误解决 + 自己的经验

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 20.0px Times; color: #333333; background-color: #fffff ...

  8. CocoaPods安装与使用

    CocoaPods简介: CocoaPods 是什么? CocoaPods 是开发 OS X 和 iOS 应用程序的一个第三方库的依赖管理工具.利用 CocoaPods,可以定义自己的依赖关系 (称作 ...

  9. << CocoaPods安装和使用教程 >>github code4app以及cocoachina 苹果官方文档

    developer.apple.com 英文搜索各个技术的官方介绍文档, 前提是英文过关 cocoachina ios最新新闻, 信息 code4app上有许多组件 http://www.code4a ...

  10. 史上最详细的CocoaPods安装教程

    虽然网上关于CocoaPods安装教程多不胜数,但是我在安装的过程中还是出现了很多错误,所以大家可以照下来步骤装一下,我相信会很好用. 前言 在iOS项目中使用第三方类库可以说是非常常见的事,但是要正 ...

随机推荐

  1. 5、html的body内标签之多行文本及下拉框

    一.多行文本 <textarea name="">默认值</textarea> 二.下拉框 1.单选 <select name="city& ...

  2. UVa 11825 Hackers' Crackdown (状压DP)

    题意:给定 n 个计算机的一个关系图,你可以停止每台计算机的一项服务,并且和该计算机相邻的计算机也会终止,问你最多能终止多少服务. 析:这个题意思就是说把 n 台计算机尽可能多的分成一些组,使得每组的 ...

  3. FileReader文件读取API

    :用来把文件读入内存,并且读取文件中的数据.FileReader接口提供了一个异步API,使用该API可以在浏览器主线程中异步访问文件系统,读取文件中的数据. 1.FileReader接口的方法 Fi ...

  4. VC++11 编译中的一些问题的解决办法

    1.  vc++ 的编译器的错误往往定位在错误的那一处,但是那一处可能在库的底层,而我们知道库,一般都不会错. 这时候应该好好看看我们自己的头文件是否正确,有可能头文件中的一些错误引发了连锁反应. 2 ...

  5. [Xcode 实际操作]八、网络与多线程-(25)实现ShareSdk的社会化分享功能

    目录:[Swift]Xcode实际操作 完成开发包的安装和配置之后,本文将演示社会化分享功能的具体开发步骤. 在项目导航区,打开并编辑程序代理文件[AppDelegate.swift] import ...

  6. XHTML学习笔记 Part4:列表

    1. 空格 如果在两个单词中间放置几个连续的空格,默认情况下只会显示一个空格,这种情况成为空格折叠.同样,如果在源文档中开始一个新行,或者放置多个连续的空行,则这些新行将被忽略并被处理为一个空格.对制 ...

  7. C#基础之析构函数

  8. django (四) model模型

    models模型 1. models 定义属性 概述 django根据属性的类型确定以下信息 ·当前选择的数据库支持字段的类型 ·渲染管理表单时使用的默认html控件 ·在管理站点最低限度的验证 dj ...

  9. springMVC-接收数据-参数绑定

    接收数据-参数绑定 #Method Arguments概观 Same in Spring WebFlux The table below shows supported controller meth ...

  10. oracle 数据库 存储过程

    destinct(去除重复行), to_char(转换自符串), to_date(日期格式函数), substr(截取自符串), lower(将字母转换为小写), upper(将字母转换为小写), t ...