-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
370 lines (285 loc) · 25.7 KB
/
Copy pathindex.html
File metadata and controls
370 lines (285 loc) · 25.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generated-by" content="Markdown PRO, http://markdownpro.com"/>
<title></title>
<style type="text/css">
html,body{margin:0;padding:0;}
body {padding: 20px}
h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,cite,code,del,dfn,em,img,q,s,samp,small,strike,strong,sub,sup,tt,var,dd,dl,dt,li,ol,ul,fieldset,form,label,legend,button,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;font-weight:normal;font-style:normal;font-size:100%;line-height:1;font-family:inherit;}
table{border-collapse:collapse;border-spacing:0;}
ol,ul{list-style:none;}
q:before,q:after,blockquote:before,blockquote:after{content:"";}
html{overflow-y:scroll;font-size:100%;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;}
a:focus{outline:thin dotted;}
a:hover,a:active{outline:0;}
article,aside,details,figcaption,figure,footer,header,hgroup,nav,section{display:block;}
audio,canvas,video{display:inline-block;*display:inline;*zoom:1;}
audio:not([controls]){display:none;}
sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline;}
sup{top:-0.5em;}
sub{bottom:-0.25em;}
img{border:0;-ms-interpolation-mode:bicubic;}
button,input,select,textarea{font-size:100%;margin:0;vertical-align:baseline;*vertical-align:middle;}
button,input{line-height:normal;*overflow:visible;}
button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0;}
button,input[type="button"],input[type="reset"],input[type="submit"]{cursor:pointer;-webkit-appearance:button;}
input[type="search"]{-webkit-appearance:textfield;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;}
input[type="search"]::-webkit-search-decoration{-webkit-appearance:none;}
textarea{overflow:auto;vertical-align:top;}
html,body{background-color:#ffffff;}
body{margin:0;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;font-weight:normal;line-height:18px;color:#404040;}
.container{width:940px;margin-left:auto;margin-right:auto;zoom:1;}.container:before,.container:after{display:table;content:"";zoom:1;*display:inline;}
.container:after{clear:both;}
.container-fluid{position:relative;min-width:940px;padding-left:20px;padding-right:20px;zoom:1;}.container-fluid:before,.container-fluid:after{display:table;content:"";zoom:1;*display:inline;}
.container-fluid:after{clear:both;}
.container-fluid>.sidebar{float:left;width:220px;}
.container-fluid>.content{margin-left:240px;}
a{color:#0069d6;text-decoration:none;line-height:inherit;font-weight:inherit;}a:hover{color:#00438a;text-decoration:underline;}
.pull-right{float:right;}
.pull-left{float:left;}
.hide{display:none;}
.show{display:block;}
.row{zoom:1;margin-left:-20px;}.row:before,.row:after{display:table;content:"";zoom:1;*display:inline;}
.row:after{clear:both;}
p{font-size:13px;font-weight:normal;line-height:18px;margin-bottom:9px;}p small{font-size:11px;color:#bfbfbf;}
h1,h2,h3,h4,h5,h6{font-weight:bold;color:#404040;}h1 small,h2 small,h3 small,h4 small,h5 small,h6 small{color:#bfbfbf;}
h1{margin-bottom:18px;font-size:30px;line-height:36px;}h1 small{font-size:18px;}
h2{font-size:24px;line-height:36px;}h2 small{font-size:14px;}
h3,h4,h5,h6{line-height:36px;}
h3{font-size:18px;}h3 small{font-size:14px;}
h4{font-size:16px;}h4 small{font-size:12px;}
h5{font-size:14px;}
h6{font-size:13px;color:#bfbfbf;text-transform:uppercase;}
ul,ol{margin:0 0 18px 25px;}
ul ul,ul ol,ol ol,ol ul{margin-bottom:0;}
ul{list-style:disc;}
ol{list-style:decimal;}
li{line-height:18px;color:#808080;}
ul.unstyled{list-style:none;margin-left:0;}
dl{margin-bottom:18px;}dl dt,dl dd{line-height:18px;}
dl dt{font-weight:bold;}
dl dd{margin-left:9px;}
hr{margin:20px 0 19px;border:0;border-bottom:1px solid #eee;}
strong{font-style:inherit;font-weight:bold;}
em{font-style:italic;font-weight:inherit;line-height:inherit;}
.muted{color:#bfbfbf;}
blockquote{margin-bottom:18px;border-left:5px solid #eee;padding-left:15px;}blockquote p{font-size:14px;font-weight:300;line-height:18px;margin-bottom:0;}
blockquote small{display:block;font-size:12px;font-weight:300;line-height:18px;color:#bfbfbf;}blockquote small:before{content:'\2014 \00A0';}
address{display:block;line-height:18px;margin-bottom:18px;}
code,pre{padding:0 3px 2px;font-family:Monaco, Andale Mono, Courier New, monospace;font-size:12px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px;}
code{padding:1px 3px;}
pre{background-color:#f5f5f5;display:block;padding:8.5px;margin:0 0 18px;line-height:18px;font-size:12px;border:1px solid #ccc;border:1px solid rgba(0, 0, 0, 0.15);-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px;white-space:pre;white-space:pre-wrap;word-wrap:break-word;}
form{margin-bottom:18px;}
fieldset{margin-bottom:18px;padding-top:18px;}fieldset legend{display:block;padding-left:150px;font-size:19.5px;line-height:1;color:#404040;*padding:0 0 5px 145px;*line-height:1.5;}
form .clearfix{margin-bottom:18px;zoom:1;}form .clearfix:before,form .clearfix:after{display:table;content:"";zoom:1;*display:inline;}
form .clearfix:after{clear:both;}
label,input,select,textarea{font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;font-weight:normal;line-height:normal;}
label{padding-top:6px;font-size:13px;line-height:18px;float:left;width:130px;text-align:right;color:#404040;}
form .input{margin-left:150px;}
input[type=checkbox],input[type=radio]{cursor:pointer;}
input,textarea,select,.uneditable-input{display:inline-block;width:210px;height:18px;padding:4px;font-size:13px;line-height:18px;color:#808080;border:1px solid #ccc;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px;}
input[type=checkbox],input[type=radio]{width:auto;height:auto;padding:0;margin:3px 0;*margin-top:0;line-height:normal;border:none;}
input[type=file]{background-color:#ffffff;padding:initial;border:initial;line-height:initial;-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;}
input[type=button],input[type=reset],input[type=submit]{width:auto;height:auto;}
select,input[type=file]{height:27px;line-height:27px;*margin-top:4px;}
select[multiple]{height:inherit;}
textarea{height:auto;}
.uneditable-input{background-color:#ffffff;display:block;border-color:#eee;-webkit-box-shadow:inset 0 1px 2px rgba(0, 0, 0, 0.025);-moz-box-shadow:inset 0 1px 2px rgba(0, 0, 0, 0.025);box-shadow:inset 0 1px 2px rgba(0, 0, 0, 0.025);cursor:not-allowed;}
:-moz-placeholder{color:#bfbfbf;}
::-webkit-input-placeholder{color:#bfbfbf;}
input,textarea{-webkit-transition:border linear 0.2s,box-shadow linear 0.2s;-moz-transition:border linear 0.2s,box-shadow linear 0.2s;-ms-transition:border linear 0.2s,box-shadow linear 0.2s;-o-transition:border linear 0.2s,box-shadow linear 0.2s;transition:border linear 0.2s,box-shadow linear 0.2s;-webkit-box-shadow:inset 0 1px 3px rgba(0, 0, 0, 0.1);-moz-box-shadow:inset 0 1px 3px rgba(0, 0, 0, 0.1);box-shadow:inset 0 1px 3px rgba(0, 0, 0, 0.1);}
input:focus,textarea:focus{outline:0;border-color:rgba(82, 168, 236, 0.8);-webkit-box-shadow:inset 0 1px 3px rgba(0, 0, 0, 0.1),0 0 8px rgba(82, 168, 236, 0.6);-moz-box-shadow:inset 0 1px 3px rgba(0, 0, 0, 0.1),0 0 8px rgba(82, 168, 236, 0.6);box-shadow:inset 0 1px 3px rgba(0, 0, 0, 0.1),0 0 8px rgba(82, 168, 236, 0.6);}
input[type=file]:focus,input[type=checkbox]:focus,select:focus{-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;outline:1px dotted #666;}
form div.clearfix.error{background:#fae5e3;padding:10px 0;margin:-10px 0 10px;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;}form div.clearfix.error>label,form div.clearfix.error span.help-inline,form div.clearfix.error span.help-block{color:#9d261d;}
form div.clearfix.error input,form div.clearfix.error textarea{border-color:#c87872;-webkit-box-shadow:0 0 3px rgba(171, 41, 32, 0.25);-moz-box-shadow:0 0 3px rgba(171, 41, 32, 0.25);box-shadow:0 0 3px rgba(171, 41, 32, 0.25);}form div.clearfix.error input:focus,form div.clearfix.error textarea:focus{border-color:#b9554d;-webkit-box-shadow:0 0 6px rgba(171, 41, 32, 0.5);-moz-box-shadow:0 0 6px rgba(171, 41, 32, 0.5);box-shadow:0 0 6px rgba(171, 41, 32, 0.5);}
form div.clearfix.error .input-prepend span.add-on,form div.clearfix.error .input-append span.add-on{background:#f4c8c5;border-color:#c87872;color:#b9554d;}
table{width:100%;margin-bottom:18px;padding:0;border-collapse:separate;*border-collapse:collapse;font-size:13px;border:1px solid #ddd;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;}table th,table td{padding:10px 10px 9px;line-height:18px;text-align:left;}
table th{padding-top:9px;font-weight:bold;vertical-align:middle;border-bottom:1px solid #ddd;}
table td{vertical-align:top;}
table th+th,table td+td{border-left:1px solid #ddd;}
table tr+tr td{border-top:1px solid #ddd;}
table tbody tr:first-child td:first-child{-webkit-border-radius:4px 0 0 0;-moz-border-radius:4px 0 0 0;border-radius:4px 0 0 0;}
table tbody tr:first-child td:last-child{-webkit-border-radius:0 4px 0 0;-moz-border-radius:0 4px 0 0;border-radius:0 4px 0 0;}
table tbody tr:last-child td:first-child{-webkit-border-radius:0 0 0 4px;-moz-border-radius:0 0 0 4px;border-radius:0 0 0 4px;}
table tbody tr:last-child td:last-child{-webkit-border-radius:0 0 4px 0;-moz-border-radius:0 0 4px 0;border-radius:0 0 4px 0;}
.zebra-striped tbody tr:nth-child(odd) td{background-color:#f9f9f9;}
.zebra-striped tbody tr:hover td{background-color:#f5f5f5;}
.zebra-striped .header{cursor:pointer;}.zebra-striped .header:after{content:"";float:right;margin-top:7px;border-width:0 4px 4px;border-style:solid;border-color:#000 transparent;visibility:hidden;}
.zebra-striped .header:hover:after{visibility:visible;}
footer{margin-top:17px;padding-top:17px;border-top:1px solid #eee;}
.page-header{margin-bottom:17px;border-bottom:1px solid #ddd;-webkit-box-shadow:0 1px 0 rgba(255, 255, 255, 0.5);-moz-box-shadow:0 1px 0 rgba(255, 255, 255, 0.5);box-shadow:0 1px 0 rgba(255, 255, 255, 0.5);}.page-header h1{margin-bottom:8px;}
.close{float:right;color:#000000;font-size:20px;font-weight:bold;line-height:13.5px;text-shadow:0 1px 0 #ffffff;filter:alpha(opacity=20);-khtml-opacity:0.2;-moz-opacity:0.2;opacity:0.2;}.close:hover{color:#000000;text-decoration:none;filter:alpha(opacity=40);-khtml-opacity:0.4;-moz-opacity:0.4;opacity:0.4;}
pre {
padding: 0;
margin: 10px 0px 10px;
overflow: auto; /*--If the Code exceeds the width, a scrolling is available--*/
overflow-Y: hidden; /*--Hides vertical scroll created by IE--*/
}
pre code {
margin: 5px; /*--Left Margin--*/
padding: 0px;
display: block;
line-height: 18px;
}
.center { text-align:center}
.left {text-align:left}
.right {text-align:right}
</style><style type="text/css">
/* nabbed from bundle_common.css */
*{margin:0;padding:0;}
html,body{color:black;}
body{font:13.34px helvetica,arial,freesans,clean,sans-serif;}
table{font-size:inherit;font:100%;}
input[type=text],input[type=password],input[type=image],textarea{font:99% helvetica,arial,freesans,sans-serif;}
select,option{padding:0 .25em;}
optgroup{margin-top:.5em;}
pre,code{font:12px Monaco,"Courier New","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace;}
body *{line-height:1.4em;}
p{margin:1em 0;}
img{border:0;}
abbr{border-bottom:none;}
html{overflow-y:scroll;}
a{color:#4183c4;text-decoration:none;}
a:hover{text-decoration:underline;}
h2,h3{margin:1em 0;}
body {
background-color: #F8F8F8;
padding: 20px;
}
body:after {
content: "";
}
/* nabbed from bundle_github.css (.wikistyle) */
h1,h2,h3,h4,h5,h6{border:0!important;}
h1{font-size:170%!important;border-top:4px solid #aaa!important;padding-top:.5em!important;margin-top:1.5em!important;}
h1:first-child{margin-top:0!important;padding-top:.25em!important;border-top:none!important;}
h2{font-size:150%!important;margin-top:1.5em!important;border-top:4px solid #e0e0e0!important;padding-top:.5em!important;}
h3{margin-top:1em!important;}
hr{border:1px solid #ddd;}
p{margin:1em 0!important;line-height:1.5em!important;}
a.absent{color:#a00;}
ul{margin:1em 0 1em 2em!important;}
ol{margin:1em 0 1em 2em!important;}
ul li,ol li{margin-top:.5em;margin-bottom:.5em;}
ul ul,ul ol,ol ol,ol ul{margin-top:0!important;margin-bottom:0!important;}
blockquote{margin:1em 0!important;border-left:5px solid #ddd!important;padding-left:.6em!important;color:#555!important;}
dt{font-weight:bold!important;margin-left:1em!important;}
dd{margin-left:2em!important;margin-bottom:1em!important;}
table{margin:1em 0!important;}
table th{border-bottom:1px solid #bbb!important;padding:.2em 1em!important;}
table td{border-bottom:1px solid #ddd!important;padding:.2em 1em!important;}
pre{margin:1em 0;font-size:12px;background-color:#eee;border:1px solid #ddd;padding:5px;line-height:1.5em;color:#444;overflow:auto;-webkit-box-shadow:rgba(0,0,0,0.07) 0 1px 2px inset;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px;}
pre::-webkit-scrollbar{height:8px;width:8px;}
pre::-webkit-scrollbar-track-piece{margin-bottom:10px;background-color:#e5e5e5;border-bottom-left-radius:4px 4px;border-bottom-right-radius:4px 4px;border-top-left-radius:4px 4px;border-top-right-radius:4px 4px;}
pre::-webkit-scrollbar-thumb:vertical{height:25px;background-color:#ccc;-webkit-border-radius:4px;-webkit-box-shadow:0 1px 1px rgba(255,255,255,1);}
pre::-webkit-scrollbar-thumb:horizontal{width:25px;background-color:#ccc;-webkit-border-radius:4px;}
pre code{padding:0!important;font-size:12px!important;background-color:#eee!important;border:none!important;}
code{font-size:12px!important;background-color:#f8f8ff!important;color:#444!important;padding:0 .2em!important;border:1px solid #dedede!important;}
a code,a:link code,a:visited code{color:#4183c4!important;}
img{max-width:100%;}
</style></head>
<body>
<h1>提 示:蓝色加粗部分为修改部分</h1>
<p>如果使用的是cocoapod 引入的时候是 #import <Masonry/Masonry.h>
如果是手动添加的为#import “Masonry.h"
CocoaPods是什么?
当你开发iOS应用时,会经常使用到很多第三方开源类库,比如JSONKit,AFNetWorking等等。可能某个类库又用到其他类库,所以要使用它,必须得另外下载其他类库,而其他类库又用到其他类库,“子子孙孙无穷尽也”,这也许是比较特殊的情况。总之小编的意思就是,手动一个个去下载所需类库十分麻烦。另外一种常见情况是,你项目中用到的类库有更新,你必须得重新下载新版本,重新加入到项目中,十分麻烦。如果能有什么工具能解决这些恼人的问题,那将“善莫大焉”。所以,你需要 CocoaPods。</p>
<p>CocoaPods应该是iOS最常用最有名的类库管理工具了,上述两个烦人的问题,通过cocoaPods,只需要一行命令就可以完全解决,当然前提是你必须正确设置它。重要的是,绝大部分有名的开源类库,都支持CocoaPods。所以,作为iOS程序员的我们,掌握CocoaPods的使用是必不可少的基本技能了。</p>
<h2>如何下载和安装CocoaPods?</h2>
<p>在安装CocoaPods之前,首先要在本地安装好Ruby环境。至于如何在Mac中安装好Ruby环境,请google一下,本文不再涉及。</p>
<p>假如你在本地已经安装好Ruby环境,那么下载和安装CocoaPods将十分简单,只需要一行命令。在Terminator(也就是终端)中输入以下命令(注意,本文所有命令都是在终端中输入并运行的。什么,你不知道什么是终端?那请小编吃饭,小编告诉你):</p>
<p>sudo gem install cocoapods</p>
<h2>但是,且慢。如果你在天朝,在终端中敲入这个命令之后,会发现半天没有任何反应。原因无他,因为那堵墙阻挡了cocoapods.org。(你会问,我靠,这都要墙!是的,小编也纳闷。)</h2>
<p>但是,是的,又但是(不过是个可喜的“但是”)。我们可以用淘宝的Ruby镜像来访问cocoapods。按照下面的顺序在终端中敲入依次敲入命令:</p>
<p>$ gem sources --remove <a href="https://rubygems.org/">https://rubygems.org/</a>
//等有反应之后再敲入以下命令
$ gem sources -a <a href="http://ruby.taobao.org/">http://ruby.taobao.org/</a></p>
<p>为了验证你的Ruby镜像是并且仅是taobao,可以用以下命令查看:</p>
<p>$ gem sources -l</p>
<p>只有在终端中出现下面文字才表明你上面的命令是成功的:</p>
<p>*** CURRENT SOURCES ***</p>
<p><a href="http://ruby.taobao.org/">http://ruby.taobao.org/</a></p>
<p>上面所有的命令完成之时,在小编的终端上是这个的样子:</p>
<h1>这时候,你再次在终端中运行:</h1>
<p>$ sudo gem install cocoapods</p>
<p>等上十几秒钟,CocoaPods就可以在你本地下载并且安装好了,不再需要其他设置。</p>
<p>敲入以上命令时,小编终端上是这个样子的(由于太长,仅截取前面一部分):</p>
<p>看到这里,你心里会不会说,我靠!太爽了,这么容易就可以下载并且安装好了!是的,小编也是这么想的。</p>
<p>如果你的gem太老,pod setup也会有问题,在执行pod setup之前需要升级下你的gem</p>
<p>sudo gem update --system</p>
<p>CocoPods就是这么简单,使用也十分简单。继续往下看吧。</p>
<h2>如何使用CocoaPods?</h2>
<p>好了,安装好CocoPods之后,接下来就是使用它。所幸,使用CocoPods和安装它一样简单,也是通过一两行命令就可以搞定。</p>
<p>小编在这里用两种使用场景来具体说明如何使用CocoaPods。</p>
<p>场景1:利用CocoaPods,在项目中导入AFNetworking类库</p>
<p>AFNetworking类库在GitHub地址是:<a href="https://github.com/AFNetworking/AFNetworking">https://github.com/AFNetworking/AFNetworking</a></p>
<p>为了确定AFNetworking是否支持CocoaPods,可以用CocoaPods的搜索功能验证一下。在终端中输入:</p>
<p>$ pod search AFNetworking</p>
<p>过几秒钟之后,你会在终端中看到关于AFNetworking类库的一些信息。比如:</p>
<p>这说明,AFNetworking是支持CocoaPods,所以我们可以利用CocoaPods将AFNetworking导入你的项目中。</p>
<p>首先,我们需要在我们的项目中加入CocoaPods的支持。你可以跟随小编的步骤,先利用Xcode创建一个名字CocoaPodsDemo的项目,用于以下的教程。创建好之后,在继续下一步之前,小编先截图,看看项目没有支持CocoaPods时的项目Xcode目录结构:</p>
<p>上图等一下要跟项目支持CocoaPods之后的项目Xcode目录结构做对比。</p>
<p>你看到这里也许会问,CocoaPods为什么能下载AFNetworking呢,而不是下载其他类库呢?这个问题的答案是,有个文件来控制CocoaPods该下载什么。这个文件就叫做“Podfile”(注意,一定得是这个文件名,而且没有后缀)。你创建一个Podfile文件,然后在里面添加你需要下载的类库,也就是告诉CocoaPods,“某某和某某和某某某,快到碗里来!”。每个项目只需要一个Podfile文件。</p>
<p>好吧,废话少说,我们先创建这个神奇的PodFile。在终端中进入(cd命令)你项目所在目录,然后在当前目录下,利用vim创建Podfile,运行:</p>
<p>$ 命令为:sudo vim Podfile (此行命令新建的Podfile文件是只读的,需要改成可写的),执行此命令后点击键盘上的i(插入Insert)</p>
<p>然后在Podfile文件中输入以下文字:</p>
<p>pod "AFNetworking", "~> 2.0"</p>
<p>注意,这段文字不是小编凭空生成的,可以在AFNetworking的github页面找到。这两句文字的意思是,当前AFNetworking支持的iOS最高版本是iOS 7.0, 要下载的AFNetworking版本是2.0。</p>
<p>然后保存退出。vim环境下,保存退出命令是:</p>
<p>:wq (在退出之前先点击键盘上的esc键,然后再执行此命令)</p>
<p>这时候,你会发现你的项目目录中,出现一个名字为Podfile的文件,而且文件内容就是你刚刚输入的内容。注意,Podfile文件应该和你的工程文件.xcodeproj在同一个目录下。</p>
<p>这时候,你就可以利用CocoPods下载AFNetworking类库了。还是在终端中的当前项目目录下,运行以下命令:</p>
<p>$ pod install </p>
<p>因为是在你的项目中导入AFNetworking,这就是为什么这个命令需要你进入你的项目所在目录中运行。</p>
<p>运行上述命令之后,小编的终端出现以下信息:</p>
<p>EricmatoMacBook-Pro:CocoaPodsDemo ericwang$ pod install
Analyzing dependencies
Downloading dependencies
Installing AFNetworking (2.0.2)
Generating Pods project
Integrating client project</p>
<p>[!] From now on use <code>CocoaPodsDemo.xcworkspace</code>.</p>
<p>注意最后一句话,意思是:以后打开项目就用 CocoaPodsDemo.xcworkspace 打开,而不是之前的.xcodeproj文件。</p>
<p>你也许会郁闷,为什么会出现.xcodeproj(xcworkspace)文件呢。这正是你刚刚运行$ pod install命令产生的新文件。除了这个文件,你会发现还多了另外一个文件“Podfile.lock”和一个文件夹“Pods”。 点击 CocoaPodsDemo.xcworkspace 打开之后工程之后,项目Xcode目录结构如下图:</p>
<p>你会惊喜地发现,AFNetwoking已经成功导入项目了(红框部分)!</p>
<p>现在,你就可以开始使用AFNetworking.h啦。可以稍微测试一下,在你的项目任意代码文件中输入:</p>
<h1>import <AFNetworking.h></h1>
<p>或者</p>
<h1>import "AFNetworking.h"</h1>
<p>然后编译,看看是否出错。如果你严格按照小编上述的步骤来,是不可能出错的啦。</p>
<p>至此,CocoPods的第一个应用场景讲述完毕。别看小编写了这么多,其实过程是十分简单的。总结一下就是:</p>
<p>先在项目中创建Podfile,Podfile的内容是你想导入的类库。一般类库的原作者会告诉你导入该类库应该如何写Podfile;
运行命令:`$ pod install.
cocoaPods 将所有的依赖库都放到另一个名为Pods项目中,然后让主项目依赖Pods项目,这样,源码管理工作都从主项目移到了Pods项目中。发现的一些技术细节有:</p>
<p>Pods项目最终会编译成一个名为libPods.a的文件,主项目只需要依赖这个.a文件即可。
对于资源文件,CocoaPods提供了一个名为Pods-resources.sh的bash脚本,该脚本在每次项目编译的时候都会执行,将第三方库的各种资源文件复制到目标目录中。
CocoaPods通过一个名为Pods.xcconfig的文件来在编译时设置所有的依赖和参数。
下面,小编继续讲述第二种使用场景。</p>
<p>场景2:如何正确编译运行一个包含CocoPods类库的项目</p>
<p>你也许曾经遇到过(特别是新手iOS开发者)这种情况,好不容易在GitHub上找到一份代码符合自己想需求,兴冲冲下载下来,一编译,傻眼了,发现有各种各样错误。一看,原来是缺失了各种其他第三方类库。这时候莫慌,你再仔细一看,会发现你下载的代码包含了Podfile。没错,这意味着你可以用CocoaPods很方便下载所需要的类库。</p>
<p>下面,小编以代码 UAAppReviewManager 为例来说明如何正确编译运行一个包含CocoPods类库的项目。</p>
<p>UAAppReviewManager是一个能够让你方便地将提醒用户评分的功能加入你的应用中。当你去UAAppReviewManager的GitHub地址下载这份代码之后,打开Example工程(UAAppReviewManagerExample),编译,你会发现Xcode报告一大堆错误,基本都是说你编译的这份代码找不到某某头文件,这就意味着你要成功编译UAAppReviewManager的Example代码,必须先导入一些第三方类库。同时你会发现在UAAppReviewManagerExample文件夹下面有三个跟CocosPods相关的文件(文件夹):Podfile,Podfile.lock和Pods,如下图:</p>
<p>用</p>
<p>这时候,打开终端,进入UAAppReviewManagerExample所在的目录,也就是和Podfile在同一目录下,和场景1一样,输入以下命令(由于已经有Podfile,所以不需要再创建Podfile):</p>
<p>$ pod update</p>
<p>过几秒(也许需要十几秒,取决于你的网络状况)之后,终端出现:</p>
<p>Analyzing dependencies
Fetching podspec for <code>UAAppReviewManager</code> from <code>../</code>
Downloading dependencies
Installing UAAppReviewManager (0.1.6)
Generating Pods project
Integrating client project</p>
<p>[!] From now on use <code>UAAppReviewManagerExample.xcworkspace</code>.</p>
<p>这时候,再回到UAAppReviewManagerExample文件夹看一看,会看到多了一个文件UAAppReviewManagerExample.xcworkspace:</p>
<p>根据终端的信息提示,你以后就需用新产生的UAAppReviewManagerExample.xcworkspace来运行这个Example代码了。</p>
<p>打开UAAppReviewManagerExample.xcworkspace,编译运行,成功!如下图:</p>
<p>注意,这里有个小问题,如果刚刚你不是输入$ pod update,而是输入$ pod install,会发现类库导入不成功,并且终端出现下面提示:</p>
<p>[!] Required version (UAAppReviewManager (from <code>../</code>)) not found for <code>UAAppReviewManager</code>.
Available versions: 0.1.6</p>
<p>这里的意思大概是Podfile文件过期,类库有升级,但是Podfile没有更改。$ pod install只会按照Podfile的要求来请求类库,如果类库版本号有变化,那么将获取失败。但是 $ pod update会更新所有的类库,获取最新版本的类库。而且你会发现,如果用了 $ pod update,再用 $ pod install 就成功了。</p>
<p>那你也许会问,什么时候用 $ pod install,什么时候用 $ pod update 呢,我又不知道类库有没有新版本。好吧,那你每次直接用 $ pod update 算了。或者先用 $ pod install,如果不行,再用 $ pod update。</p>
<p>好了,小编就啰嗦到这里吧。上述都只是CocoaPods的最基本用法。要继续研究CocoaPods其他高级用法,请点击这里CocoaPods Wiki</p>
</body>
</html>