cocoapods安装与使用

article/2025/9/22 10:06:06

CocoaPods是什么?

1.说这么一个现场,如果要引用第三方类库是不是要把他拖进项目引用或者copy,如果第三方类库更新了,你是不是又要重新应用更新啊?答案是肯定的。

2.另外一种情况,如果项目过大,且项目中有很多相对独立的功能,分工到不同人的手中维护升级开发,最后整合项目(其实可把他们看作第三方类库),是不是也会遇到copy或者引用的问题。

以上两点会导致,遇到更改就要换代码换文件,如果你的项目就一个,可以很轻松换掉,如果是10个 ,100个....估计就该抱怨了,cocoapos一个链接就搞定了,可以很好提高效率,同时有利于分工协作。

今天把cocoapods安装过程总结分享给大家。

CocoaPods安装

第一步:安装CocoaPods之前,首先要在本地安装好Ruby环境。(ruby安装 https://ruby-china.org/wiki/install_ruby_guide)

             安装ruby过程如下:

             a.确保 已经安装xCode的Command Line Tools

             b.打开终端:

ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
第二步: 当b步骤执行成功后,在终端输入:

sudo gem install cocoapods
 

            发现没有反映,别急换个方法:

       

            如果发现报:Could not find a valid gem 'cocoapods' (>= 0) in any repository 别急,这个问题说明是你的gem版本过旧了 (没有报错此步骤可以跳过)

            在终端先输入:

sudo gem update --system


            重新打开终端输入:

gem sources --remove https://rubygems.org/

            会返回:

            https://rubygems.org/ removed from sources

            在输入:
gem sources -a http://ruby.taobao.org/
            会返回:

            http://ruby.taobao.org/ added to sources

            检测一下在终端输入:
gem sources -l
            得到如下:

            *** CURRENT SOURCES ***

            http://ruby.taobao.org/

            为什么这么做?原因是国家的防火墙有点牛,猜的!

第三步:再次输入:

sudo gem install cocoapods

            等待几十秒会返回:

Fetching: multi_json-1.10.1.gem (100%)
Successfully installed multi_json-1.10.1
Fetching: activesupport-3.2.19.gem (100%)
Successfully installed activesupport-3.2.19
Fetching: nap-0.8.0.gem (100%)
Successfully installed nap-0.8.0
Fetching: json_pure-1.8.1.gem (100%)
Successfully installed json_pure-1.8.1
Fetching: fuzzy_match-2.0.4.gem (100%)
Successfully installed fuzzy_match-2.0.4
Fetching: cocoapods-core-0.33.1.gem (100%)
Successfully installed cocoapods-core-0.33.1
Fetching: claide-0.6.1.gem (100%)
Successfully installed claide-0.6.1
Fetching: colored-1.2.gem (100%)
Successfully installed colored-1.2
Fetching: xcodeproj-0.17.0.gem (100%)
Building native extensions.  This could take a while...
[!] You are using the prebuilt binary version of the xcodeproj gem.
Successfully installed xcodeproj-0.17.0
Fetching: cocoapods-downloader-0.6.1.gem (100%)
Successfully installed cocoapods-downloader-0.6.1
Fetching: cocoapods-plugins-0.2.0.gem (100%)
Successfully installed cocoapods-plugins-0.2.0
Fetching: cocoapods-try-0.3.0.gem (100%)
Successfully installed cocoapods-try-0.3.0
Fetching: netrc-0.7.7.gem (100%)
Successfully installed netrc-0.7.7
Fetching: cocoapods-trunk-0.1.4.gem (100%)
Successfully installed cocoapods-trunk-0.1.4
Fetching: escape-0.0.4.gem (100%)
Successfully installed escape-0.0.4
Fetching: open4-1.3.4.gem (100%)
Successfully installed open4-1.3.4
Fetching: cocoapods-0.33.1.gem (100%)CHANGELOG:## 0.33.1##### Bug Fixes* Fix `pod spec lint` for `json` podspecs.  [Fabio Pelosin][irrationalfab][#2157](https://github.com/CocoaPods/CocoaPods/issues/2157)* Fixed downloader issues related to `json` podspecs.  [Fabio Pelosin][irrationalfab][#2158](https://github.com/CocoaPods/CocoaPods/issues/2158)* Fixed `--no-ansi` flag in help banners.  [Fabio Pelosin][irrationalfab][#34](https://github.com/CocoaPods/CLAide/issues/34)Successfully installed cocoapods-0.33.1
Parsing documentation for multi_json-1.10.1
Installing ri documentation for multi_json-1.10.1
Parsing documentation for activesupport-3.2.19
unable to convert "\x80" from ASCII-8BIT to UTF-8 for lib/active_support/values/unicode_tables.dat, skipping
Installing ri documentation for activesupport-3.2.19
Parsing documentation for nap-0.8.0
Installing ri documentation for nap-0.8.0
Parsing documentation for json_pure-1.8.1
Installing ri documentation for json_pure-1.8.1
Parsing documentation for fuzzy_match-2.0.4
Installing ri documentation for fuzzy_match-2.0.4
Parsing documentation for cocoapods-core-0.33.1
Installing ri documentation for cocoapods-core-0.33.1
Parsing documentation for claide-0.6.1
Installing ri documentation for claide-0.6.1
Parsing documentation for colored-1.2
Installing ri documentation for colored-1.2
Parsing documentation for xcodeproj-0.17.0
Installing ri documentation for xcodeproj-0.17.0
Parsing documentation for cocoapods-downloader-0.6.1
Installing ri documentation for cocoapods-downloader-0.6.1
Parsing documentation for cocoapods-plugins-0.2.0
Installing ri documentation for cocoapods-plugins-0.2.0
Parsing documentation for cocoapods-try-0.3.0
Installing ri documentation for cocoapods-try-0.3.0
Parsing documentation for netrc-0.7.7
Installing ri documentation for netrc-0.7.7
Parsing documentation for cocoapods-trunk-0.1.4
Installing ri documentation for cocoapods-trunk-0.1.4
Parsing documentation for escape-0.0.4
Installing ri documentation for escape-0.0.4
Parsing documentation for open4-1.3.4
Installing ri documentation for open4-1.3.4
Parsing documentation for cocoapods-0.33.1
Installing ri documentation for cocoapods-0.33.1
17 gems installed

我的终端:


CocoaPods使用

使用很简单如在终端输入:

pod search AFNetworking

结果返回:

Setting up CocoaPods master repo

嚓,知道吗?我等了足足半个小时。所以请内心等待.

半小时之后返回:

Setup completed (read-only access)



-> AFNetworking (2.3.1)

   A delightful iOS and OS X networking framework.

   pod 'AFNetworking', '~> 2.3.1'

   - Homepage: https://github.com/AFNetworking/AFNetworking

   - Source:   https://github.com/AFNetworking/AFNetworking.git

   - Versions: 2.3.1, 2.3.0, 2.2.4, 2.2.3, 2.2.2, 2.2.1, 2.2.0, 2.1.0, 2.0.3, 2.0.2, 2.0.1,

   2.0.0, 2.0.0-RC3, 2.0.0-RC2, 2.0.0-RC1, 1.3.4, 1.3.3, 1.3.2, 1.3.1, 1.3.0, 1.2.1, 1.2.0,

   1.1.0, 1.0.1, 1.0, 1.0RC3, 1.0RC2, 1.0RC1, 0.10.1, 0.10.0, 0.9.2, 0.9.1, 0.9.0, 0.7.0,

   0.5.1 [master repo]

   - Sub specs:

     - AFNetworking/Serialization (2.3.1)

     - AFNetworking/Security (2.3.1)

     - AFNetworking/Reachability (2.3.1)

     - AFNetworking/NSURLConnection (2.3.1)

     - AFNetworking/NSURLSession (2.3.1)

     - AFNetworking/UIKit (2.3.1)



-> AFNetworking+AutoRetry (0.0.3)

   Auto Retries for AFNetworking requests

   pod 'AFNetworking+AutoRetry', '~> 0.0.3'

   - Homepage: https://github.com/shaioz/AFNetworking-AutoRetry

   - Source:   https://github.com/shaioz/AFNetworking-AutoRetry.git

   - Versions: 0.0.3, 0.0.2, 0.0.1 [master repo]



-> AFNetworking+streaming (0.5)

   A very quick extension to AFNetworking that adds stream based parsing

   pod 'AFNetworking+streaming', '~> 0.5'

   - Homepage: https://github.com/deanWombourne/AFNetworking-streaming

   - Source:   https://github.com/deanWombourne/AFNetworking-streaming.git

   - Versions: 0.5, 0.4, 0.3, 0.2, 0.1 [master repo]

   - Sub specs:

     - AFNetworking+streaming/Core (0.5)

     - AFNetworking+streaming/Json (0.5)



-> AFNetworking-MUResponseSerializer (1.0.0)

   Automatically serialize JSON response to your object model. It also works with

   NSManagedObjects.

   pod 'AFNetworking-MUResponseSerializer', '~> 1.0.0'

   - Homepage: https://github.com/Ulianko/AFNetworking-MUResponseSerializer

   - Source:   https://github.com/Ulianko/AFNetworking-MUResponseSerializer.git

   - Versions: 1.0.0 [master repo]



-> AFNetworking-RACExtensions (0.1.4)

   AFNetworking-RACExtensions is a delightful extension to the AFNetworking classes for iOS

   and Mac OS X.

   pod 'AFNetworking-RACExtensions', '~> 0.1.4'

   - Homepage: https://github.com/CodaFi/AFNetworking-RACExtensions

   - Source:   https://github.com/CodaFi/AFNetworking-RACExtensions.git

   - Versions: 0.1.4, 0.1.2, 0.1.1, 0.0.1 [master repo]



-> AFNetworking-ReactiveCocoa (0.0.2)

   Make AFNetworking reactive.

   pod 'AFNetworking-ReactiveCocoa', '~> 0.0.2'

   - Homepage: https://github.com/uasi/AFNetworking-ReactiveCocoa

   - Source:   https://github.com/uasi/AFNetworking-ReactiveCocoa.git

   - Versions: 0.0.2, 0.0.1 [master repo]



-> AFNetworking-Synchronous (0.2.0)

   Synchronous requests for AFNetworking

   pod 'AFNetworking-Synchronous', '~> 0.2.0'

   - Homepage: https://github.com/paulmelnikow/AFNetworking-Synchronous

   - Source:   https://github.com/paulmelnikow/AFNetworking-Synchronous.git

   - Versions: 0.2.0, 0.1.0 [master repo]



-> AFNetworking2-RACExtensions (0.0.1)

   AFNetworking-RACExtensions is a delightful extension to the AFNetworking classes for iOS

   and Mac OS X.

   pod 'AFNetworking2-RACExtensions', '~> 0.0.1'

   - Homepage: https://github.com/knshiro/AFNetworking-RACExtensions

   - Source:   https://github.com/knshiro/AFNetworking-RACExtensions.git

   - Versions: 0.0.1 [master repo]



-> CollectionUtils-AFNetworking (1.0.1)

   CollectionUtils additions for AFNetworking.

   pod 'CollectionUtils-AFNetworking', '~> 1.0.1'

   - Homepage: https://github.com/kishikawakatsumi/CollectionUtils

   - Source:   https://github.com/kishikawakatsumi/CollectionUtils.git

   - Versions: 1.0.1, 1.0.0 [master repo]



-> CollectionUtils-AFNetworking-1.3 (1.0.1)

   CollectionUtils additions for AFNetworking 1.3.x.

   pod 'CollectionUtils-AFNetworking-1.3', '~> 1.0.1'

   - Homepage: https://github.com/kishikawakatsumi/CollectionUtils

   - Source:   https://github.com/kishikawakatsumi/CollectionUtils.git

   - Versions: 1.0.1, 1.0.0 [master repo]





http://chatgpt.dhexx.cn/article/IT88VmkE.shtml

相关文章

CocoaPods安装方法(2021最新版)

CocoaPods简介: CocoaPods是一个用Ruby写的、负责管理iOS项目中第三方开源库的工具,CocoaPods能让我们集中的、统一管理第三方开源库,为我们节省设置和更新第三方开源库的时间。 CocoaPods安装: 下面就正式开始安装CocoaPods,命令中间可能…

CocoaPod的安装

更新以前大家都是根据淘宝镜像来安装cocoapods,此篇文章也和大多数博文内容相仿。后来换电脑时,同事说淘宝镜像已经不能用了,网上又重新查看教程,确实都是这么说的!(好吧,我确实比较懒&#xff…

cocoapods安装和使用

CocoaPods应该是iOS最常用最有名的类库管理工具了,通过cocoaPods,只需要一行命令就可以完全解决,当然前提是你必须正确设置它。重要的是,绝大部分有名的开源类库,都支持CocoaPods。作为iOS程序员,掌握Cocoa…

全网最新CocoaPods安装教程(持续更新)

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

Cocoapods安装及使用

1.CocoaPods安装是基于ruby环境的,所以要安装CocoaPods先要安装Ruby环境,国内不能直接安装,只能通过VPN或淘宝的Ruby镜像来访问。 通过Ruby镜像来访问在终端输入以下命令: gem sources --remove https://rubygems.org/ 等有反应后&#xff0c…

CocoaPods安装

1.查询Ruby的源地址 $ gem source -l查询结果: CURRENT SOURCES ***https://rubygems.org2.移除系统Ruby源 $ gem sources --remove https://rubygems.org显示结果: https://rubygems.org removed from sources3.更换为国内Ruby镜像源 $ gem sourc…

iOS开发-CocoaPods安装和使用教程

原文链接: iOS开发-CocoaPods安装和使用教程 本文是对原文一些错误的修正已经添加了自己的理解。 CocoaPods安装和使用教程 Code4App 原创文章。转载请注明出处:http://code4app.com/article/cocoapods-install-usage 目录 CocoaPods是什么?如何下载和…

2021年CocoaPods安装方法

写在前面的话: 在执行下面的任何步骤中遇到 中断、进度缓慢、各种失败等问题时, 请严格遵守以下原则: 1、重试、重试、重试,没准多试几次就好了呢; 2、切换为手机移动网络(已验证过多次,可行&a…

CocoaPods安装和使用教程

CocoaPods安装和使用教程 Code4App 原创文章。转载请注明出处:http://code4app.com/article/cocoapods-install-usage 目录 CocoaPods是什么?如何下载和安装CocoaPods?如何使用CocoaPods? 场景1:利用CocoaPods&#…

CocoaPods安装方法 (M1芯片)-完美安装成功

1、新的电脑基本上都已经安装好最新的ruby了,不放心的可以检查一下ruby的版本和sources, ruby -v gem sources -l 2、查看Homebrew: brew -v 2.1)MacOs M1安装Homebrew: /bin/zsh -c "$(curl -fsSL https://gitee.com…

最新cocoapods安装流程

一、安装homebrew Homebrew是一款包管理工具,主要有四个部分组成: brew、homebrew-core 、homebrew-cask、homebrew-bottles。 打开终端输入: /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"下面…

CocoaPods的安装与使用

1、一般情况下, 每个人从共享库把项目下载下来之后, 都会执行pod install命令安装,而不是选择 pod update,这样是为了保证大家使用的第三方框架版本一致。如果以后大家需要统一升级第三方框架, 那么每个人在执行 pod update 2、--repo-update检查框架有没…

Cocoapods的安装

一、 CocoaPods简介 开发ios要用到很多第三方开源类库,例如Masonry、AFNetWorking、JSONKit等等。而这些库可能又依赖于其它类库,那么我们又得手动下载其它类库,如果库有更新,又得手动下载新版本的并删除掉项目中的旧版本的&…

Cocoapods安装教程

作者:魔女小溪 出处:http://www.cnblogs.com/angelgril/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利. 备注&…

DTO及其处理

层间数据传输的过程就是服务的执行者将数据返回给服务的调用者的过程。在非分布式系统中由于有类似Open session in view这样的“怪胎解决方案”的存在,所以层间数据传输的问题并没有充分暴露出来,但是在分布式系统中我们就能清楚地意识到层间数据传输的…

DTO笔记

我们为什么需要DTO(数据传输对象) 表现层与应用层之间是通过数据传输对象(DTO)进行交互的,数据传输对象是没有行为的POCO对象,它 的目的只是为了对领域对象进行数据封装,实现层与层之间的数据传递。为何不能直接将领域…

DTO(数据传输对象)模式

0. 写在前面 首先,这是一篇翻译文章,个人建议你可以阅读英文原文Baeldung: The DTO Pattern (Data Transfer Object),因为个人水平,很多地方翻译的不通顺和晦涩,如果你选择继续往下看,请不要高估了我的英文…

DTO介绍

先看看这张图,dto所处位置,主要是用于业务逻辑层service和表示层servlet之间的数据传输 什么是DTO(Data Transfer Object)数据传输对象? DTO是一个比较特殊的对象,他有两种存在形式: 在后端,他的存在形式…

阿里巴巴Java开发手册中的DO、DTO、BO、AO、VO、POJO定义

常用文件夹分层: pojo vo (与前端交互的所有对象,包括接参和返回)query (查询的筛选条件,前端传参和后端内部传参通用)entity (数据库表基础对象)dto(后端内…

R下载与安装详细指南

一、登陆www.r-project.org进入R官网 二、点击左侧CRAN或右侧的download R 三、在China选项,随机点击一个镜像 四、R语言可以在Linux、MAC OS和Windows上运行,根据个人的操作系统选择需要下载的镜像 五、点击下载、运行、选择中文版本 六、安装过程 …