CocoaPods安装和使用

本文详细介绍了如何在MacOS系统上安装并使用CocoaPods,包括下载、安装命令、检查Ruby和Gem版本、移除及添加镜像、安装Cocoapods等步骤,并演示了在项目中使用Pods的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下载和安装CocoaPods

下面的命令依次进行

Command命令

command meaning 命令功能

exec results 执行结果

curl -LsSf http://github.com/mxcl/homebrew/tarball/master | sudo tar xvz -C/usr/local --strip 1

brew 即 Homebrew,是Mac OSX上的软件包管理工具,能在Mac中方便的安装软件或者卸载软件, 只需要一个命令

 

ruby -v

查看ruby版本

ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]

gem -v

查看gem版本

2.0.14

gem source -r https://rubygems.org/

 移除 镜像https://rubygems.org/

https://rubygems.org/ removed from sources

gem source -a https://ruby.taobao.org

 添加淘宝镜像

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

gem sources -l

 验证Ruby镜像是并且仅是taobao

*** CURRENT SOURCES ***

https://ruby.taobao.org

sudo gem install cocoapods

安装cocoapods

Successfully installed cocoapods-0.35.0
Parsing documentation for cocoapods-0.35.0
1 gem installed

项目中使用Pods

 命令功能

command命令

exec results执行结果

file changes

demo-新建项目DemoCocoa,进入根目录

 

 

 

创建Podfile文件

  • Xcode: New file->Empty file ->named Podfile
  • Terminal: pod init(两者选其一)

 

 

 

  • pod install

Analyzing dependencies
Downloading dependencies
Generating Pods project
Integrating client project

[!] From now on use `DemoCocoa.xcworkspace`.

[!] [!] The Podfile does not contain any dependencies.

  • Podfile.lock
  • ***.xcworkspace
  • Pods (folder)
    • Headers(folder)
    • Local Podspecs(folder)
    • Mainfest.lock
    • Pods.xcodeproj
    • Target Support Files(folder)

编辑Podfile文件

在Podfile输入需要用到的类库例如:

#Podfile文件内容

platform :ios, "6.0"
pod 'AFNetworking'
pod 'JSONKit'
pod 'MBProgressHUD'
pod 'Reachability'
pod 'Base64'
pod 'OpenUDID'

如果需要查看引用的类库是否支持CocoaPods。可以用CocoaPods的搜索功能验证一下。例如在终端中输入:

pod search AFNetworking

 

 

 

  • pod install
  • pod update(二者选其一)

Installing AFNetworking (2.5.0)
Installing Base64 (1.0.1)
Installing JSONKit (1.4)

[!] Error installing JSONKit

  • Podfile.lock
  • ***.xcworkspace
  • Pods (folder)
    • Headers(folder)
    • Local Podspecs(folder)
    • Mainfest.lock
    • Pods.xcodeproj
    • Target Support Files(folder)
      • .xcconfig
      • 生产的xcconfig怎么样和App target建立关系

在pods文件夹中增加了Podfile中指定的第三方文件

Headers里面是这些第三方文件的一个引用


Refs

官网

cocoapod guide

Troubleshooting

cocoapods-install-usage

其他博客

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值