iOS.CocoaPods.0
1. CocoaPods
CocoaPods 是Objective-C (iOS and OS X) projects 的依赖管理器。
A CocoaPod (singular) is a specification for a library, usually open source.
CocoaPods (plural) is the tool for managing these specs. [1]
2. How to install CocoaPods
2.1 安装CocoaPods步骤
在终端中输入以下命令:
$ sudo gem install cocoapods
注:在终端中安装CocoaPods时可能会遇到如下问题 (感谢伟大的GFW):
"ERROR: Could not find a valid gem 'cocoapods' (>= 0), here is why:
Unable to download data from https://rubygems.org/ - Errno::ETIMEDOUT: Operation timed out - connect(2) (https://rubygems.org/quick/Marshal.4.8/cocoapods-0.33.1.gemspec.rz)"
这时候我们需要改变 gem source, 参考[4], [5]。需要在终端中执行如下命令:
$ gem sources -l
$ gem sources --remove https://rubygems.org/
$ gem sources -a https://ruby.taobao.org/
$ gem sources -l
接下来输入以下命令:
$ pod setup
This process will likely take a while as this command clones the CocoaPods Specs repository
into ~/.cocoapods/ on your computer. Ref[6]
至此CocoaPods安装完毕。
注: 如果漏掉 "$ pod setup" 命令,而直接执行"$ pod init"
会有类似以下的error信息:
"$ pod init
Setting up CocoaPods master repo
[!] /usr/bin/git clone 'https://github.com/CocoaPods/Specs.git' master --depth=1
Cloning into 'master'...
error: RPC failed; result=52, HTTP code = 0
fatal: The remote end hung up unexpectedly
/Library/Ruby/Gems/2.0.0/gems/claide-0.6.1/lib/claide/command.rb:304:in `handle_exception': undefined method `verbose?' for nil:NilClass (NoMethodError)
from /Library/Ruby/Gems/2.0.0/gems/claide-0.6.1/lib/claide/command.rb:284:in `rescue in run'
from /Library/Ruby/Gems/2.0.0/gems/claide-0.6.1/lib/claide/command.rb:274:in `run'
from /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.33.1/lib/cocoapods/command.rb:48:in `run'
from /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.33.1/bin/pod:33:in `<top (required)>'
from /usr/bin/pod:23:in `load'
from /usr/bin/pod:23:in `<main>' "
2.2 更新CocoaPods
$ [sudo] gem install cocoapods
http://guides.cocoapods.org/using/getting-started.html
更新cocoapods到指定的版本:
$ [sudo] gem install cocoapods -v VERSION
3. How to use CocoaPods
创建一个Podfile, 将依赖添加到Podfile中。
3.1 创建一个新Xcode Project, 并在该工程中使用CocoaPods
A: 如正常创建一个新工程
B: 在终端窗口中, 执行 cd 命令到 工程目录
C: 创建一个Podfile文件. ($ vim Podfile 或者 $ touch Podfile )
D: 在Podfile文件第一行指明平台和版本, 例如:
platform :ios, '6.0'
E: Add a CocoaPod by specifying pod '$PODNAME'
on a single line (????)
pod 'ObjectiveSugar'
F: 保存 Podfile.
G: 运行 $ pod install
H: 打开MyApp.xcworkspace
3.2 集成到一个已存在的workspace中
集成CocoaPods到一个存在的workspace中,需要在Podfile中额外添加一行。
将".xcworkspace"去掉后的根文件名添加到Podfile中:
workspace 'MyWorkspace'
3.3 是否应该在源代码控制中忽略Pods目录?
3.4 Podfile.lock是什么以及作用?
该文件是由Pod工具生成的:
"When this is run, CocoaPods will recursively analyze the dependencies of each project,
resolving them into a dependency graph, and serializing into a Podfile.lock
file." Ref[10]
3.5 在背后发生了什么? (What is happening behind the scenes?)
3.6 Pods 和 Submodules(git)
3.7 从submodules切换到CocoaPods
4. Demo
Ref[3]
4.1 将Pod添加到Xcode Project中
安装CocoaPods完毕后,用Xcode创建一个Project(例如:CocoaPodsDemo)后,
cd 到 CocoaPodsDemo 的目录下:
$ pwd
/Users/XiaoKL/Projects/CocoaPodsDemo
执行以下命令:
$ pod init
"$ pod init" 创建一个Podfile。
$ ls -l
total 8
drwxr-xr-x 12 XiaoKL staff 408 8 23 22:09 CocoaPodsDemo
drwxr-xr-x 5 XiaoKL staff 170 8 23 22:09 CocoaPodsDemo.xcodeproj
drwxr-xr-x 5 XiaoKL staff 170 8 23 22:09 CocoaPodsDemoTests
-rw-r--r-- 1 XiaoKL staff 160 8 23 22:52 Podfile
创建的Podfile内容如下:
"# Uncomment this line to define a global platform for your project
# platform :ios, "6.0"
target "CocoaPodsDemo" do
end
target "CocoaPodsDemoTests" do
end "
4.2 修改生成的Podfile
修改后的Podfile内容如下:
"# Uncomment this line to define a global platform for your project
platform :ios, "6.0"
target "CocoaPodsDemo" do
pod "SVProgressHUD", "0.9"
end
target "CocoaPodsDemoTests" do
end"
然后执行命令:
"$ pod install"
该命令有以下输出:
"Analyzing dependencies
Downloading dependencies
Installing SVProgressHUD (0.9)
Generating Pods project
Integrating client project
[!] From now on use `CocoaPodsDemo.xcworkspace`."
"$ pod install" 命令创建了:CocoaPodsDemo.xcworkspace, Podfile.lock和Pods, 如下可以从ls命令的时间戳上看出来。
$ ls -alG
total 16
drwxr-xr-x 9 XiaoKL staff 306 8 23 23:30 .
drwxr-xr-x 4 XiaoKL staff 136 8 23 22:09 ..
drwxr-xr-x 12 XiaoKL staff 408 8 23 22:09 CocoaPodsDemo
drwxr-xr-x 5 XiaoKL staff 170 8 23 22:09 CocoaPodsDemo.xcodeproj
drwxr-xr-x 3 XiaoKL staff 102 8 23 23:30 CocoaPodsDemo.xcworkspace
drwxr-xr-x 5 XiaoKL staff 170 8 23 22:09 CocoaPodsDemoTests
-rw-r--r-- 1 XiaoKL staff 186 8 23 23:26 Podfile
-rw-r--r-- 1 XiaoKL staff 165 8 23 23:30 Podfile.lock
drwxr-xr-x 17 XiaoKL staff 578 8 23 23:30 Pods
4.3 使用SVProgressHUD
在代码中使用SVProgressHUD,需要#import <SVProgressHUD.h>
4.4 为一个已经用CocoaPods管理的workspace添加一个新的依赖库
A: 将依赖项添加到Podfile文件中
B: 运行命令: $ pod install
4.5 pod install 卡在 "Analyzing dependencies"
A: pod install --verbose --no-repo-update
或者使用VPN。 这是因为访问github.com慢导致的。
5. 解析Podfile文件
http://guides.cocoapods.org/using/the-podfile.html
5.1 Podfile是什么?
Podfile一个规格书, 该规格书来描述Xcode工程的target的依赖关系。
The Podfile is a specification that describes the dependencies of the targets of one
or more Xcode projects. The Podfile always creates an implicit target, named default
,
which links to the first target of the user project.
podfile可以如下简单:
pod 'AFNetworking', '~> 1.0'
关于version的说明:
'> 0.1'
Any version higher than 0.1'>= 0.1'
Version 0.1 and any higher version'< 0.1'
Any version lower than 0.1'<= 0.1'
Version 0.1 and any lower version
'~> 0.1.2'
Version 0.1.2 and the versions up to 0.2, not including 0.2 and higher'~> 0.1'
Version 0.1 and the versions up to 1.0, not including 1.0 and higher'~> 0'
Version 0 and higher, this is basically the same as not having it.
version 也可以是 :head, 例如:
pod 'Objection', :head
注:在实践中,Podfile中如下写,
pod 'FMDB', '~> 2.0'
安装的是 2.5(即 当时最新的版本), 下面是console的输出:
Installing FMDB (2.5)
5.2 version冲突的解决
[Todo]
5.3 使用本地文件夹的文件
[Todo]
5.4 From a podspec in the root of a library repo.
本节示例了如何使用某个分支,某个tag,某个commit。
5.5 Podfile的语法规范
[Todo]
6. Pods在使用过程中的FQA
6.1 .pbxproj格式变为xml格式的问题
Cocoapods 0.34 在pod install 或 pod update 时会将Pods/Pods.xcodeproj/project.pbxproj
以xml的格式重写,这给我们进行merge带来了很大的挑战。
解决方法: 安装xcproj Ref[11]
6.2 pod install Vs. pod update
pod install 和 pod update的区别以及pod其它的各个命令 Ref[12]
Ref[12] Ref[14]
Reference:
1. http://ashfurrow.com/blog/getting-started-with-cocoapods-demo
2.
3. Getting Started with CocoaPods
http://ashfurrow.com/blog/getting-started-with-cocoapods-demo
该blog中讲的安装过程漏掉了"pod setup" 这一步, 参加[6]中的步骤。
介绍了一个Xcode插件:https://github.com/kattrali/cocoapods-xcode-plugin
PPT:Effective Use of Open Source Software (ToRead)
https://speakerdeck.com/ashfurrow/effective-use-of-open-source-software
4. RubyGems 镜像
http://ruby.taobao.org
5.
http://stackoverflow.com/questions/19612185/unable-to-install-cocoapods-gem-from-rubygems-org-bad-response-backend-read-e
6. Introduction to CocoaPods Tutorial (ToRead)
http://www.raywenderlich.com/64546/introduction-to-cocoapods-2
7. Streamlining Cocoa Development With CocoaPods (ToRead)
http://code.tutsplus.com/tutorials/streamlining-cocoa-development-with-cocoapods--mobile-15938
8. Using CocoaPods to Modularize a Big iOS App (ToRead)
http://dev.hubspot.com/blog/architecting-a-large-ios-app-with-cocoapods
9. Using CocoaPods to Manage Private
http://chariotsolutions.com/blog/post/using-cocoapods-to-manage-private-libraries/
CocoaPods 支持git, svn等scm工具。 如何使用CocoaPods管理私有的库,以及示例。
pod spec create projectname
10. CocoaPods
http://nshipster.com/cocoapods/
11. Generate ASCII format xcodeproj
https://github.com/CocoaPods/CocoaPods/wiki/Generate-ASCII-format-xcodeproj
12. pod 各个命令的解释
https://github.com/CocoaPods/CocoaPods/issues/760#issuecomment-46300500
13. 在cocoapods中搜索开源库/Project
https://cocoapods.org/
14. Demystifying Pod Install and Pod Update [To Read]
https://hackernoon.com/demystifying-pod-install-and-pod-update-1751dc35de43
Todo:
1. CocoaPod的工作原理是什么?
$ pod install 命令创建了一个workspace,该workspace包含了原来的project,以及一个新建的project。
这和使用subproject的方法有和不同呢?
2. .xcconfig文件的作用?
3. CocoaPods能给我们带来什么?并发式开发,or 管理大项目?
iOS.CocoaPods.0的更多相关文章
- iOS -- CocoaPods
CocoaPods 是什么? CocoaPods 是一个负责管理 iOS 项目中第三方开源库的工具.CocoaPods 的项目源码在 GitHub( https://github.com/CocoaP ...
- iOS CocoaPods 版本安装问题
今天安装salesforce中的pods,这是里面的podfile # Uncomment this line to define a global platform for your project ...
- iOS cocoapods升级及问题
安装 安装RubyCocoaPods基于Ruby语言开发而成,因此安装CocoaPods前需要安装Ruby环境.幸运的是Mac系统默认自带Ruby环境,如果没有请自行查找安装.检测是否安装Ruby:$ ...
- iOS Cocoapods的pod install出现的某个错误 but they required a higher minimum deployment target.
关于cocoapods的安装和使用的基本教程: http://my.oschina.net/vimfung/blog/182427?fromerr=j7l3DvCG 出现以下错误提示: Specs ...
- iOS - CocoaPods 第三方开源框架管理
1.CocoaPods CocoaPods 是一个负责管理 iOS 项目中第三方开源库的工具.CocoaPods 的项目源码在 Github 上管理.该项目开始于 2011 年 8 月 12 日,在这 ...
- iOS CocoaPods安装和使用图解
Cocoapods安装步骤 1.升级Ruby环境 sudo gem update --system 如果Ruby没有安装,请参考 如何在Mac OS X上安装 Ruby运行环境 2.安装CocoaPo ...
- iOS CocoaPods一些特别的用法 指定版本、版本介绍、忽略警告
简介 介绍一些CocoaPods一些特别的用法 CocoaPods github地址 CocoaPods 官方地址 1. 指定第三方库版本 1. 固定版本 target 'MyApp' do use_ ...
- iOS 从0到1搭建高可用App框架
iOS 从0到1搭建高可用App框架 最近在搭建新项目的iOS框架,一直在思考如何才能搭建出高可用App框架,能否避免后期因为代码质量问题的重构.以前接手过许多“烂代码”,架构松散,底层混乱,缺少规范 ...
- iOS:CocoaPods详解
原文地址:http://blog.csdn.net/wzzvictory/article/details/18737437 一.什么是CocoaPods 1.为什么需要CocoaPods 在进行iOS ...
随机推荐
- Linux初学时的一些常用命令(1)
查看帮助: man 命令 退出帮助目录: q 切换目录:cd cd 目录 cd 目录/目录 cd .. :上一级目录 cd / :根目录cd ~ :回家 创建目录和删除目录 mkdi ...
- 关于 uboot 的异常向量表
ldr r,address 表示将 address 地址中的内容存入 r0 中
- https://www.oschina.net/project/zhlist/326/scripting 开源
1https://www.oschina.net/project/zhlist/326/scripting
- centos mongodb
cd到mongodb目录下的bin文件夹,执行命令./mongo 运行如下: [root@namenode mongodb]# ./bin/mongo MongoDB shell version: 1 ...
- Physical (Raw) Versus Logical Backups
[Physical (Raw) Versus Logical Backups] Physical backups consist of raw copies of the directories an ...
- python-ceilometerclient命令行(终结)
ceilometerclient入口 工程ceilometerclient shell.py中的main方法 ceilometerclient目录 --ceilometerclient --commo ...
- web.xml中<security-constraint>和四种认证类型
https://blog.csdn.net/lisheng19870305/article/details/40819481 sztc开发中http请求一直发送后无响应,通过soapui定位异常信息为 ...
- 使用WebStorm自动提示nodejs的有关代码
- 可上下拖动且有浮沉动画的View
package com.ifenglian.superapp1; import android.animation.Animator;import android.animation.Animator ...
- k8s volume 基本类型分类
volume 类型 静态volume emptyDir 临时空目录, 用途,pod内多用户同享一个目录.与POD的生命周期一至,POD创建时创建,删除时删除. Hostpath 宿主机1:1映射,用途 ...