-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
653 lines (312 loc) · 29.2 KB
/
index.html
File metadata and controls
653 lines (312 loc) · 29.2 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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Migrant</title>
<meta name="author" content="Migrant">
<meta name="description" content="Jan 6th, 2015 iOS, 翻译 Comments DTrace 本文由 Migrant 翻译自 DTrace,感谢 onevcat 校对,转载请注明出处。本文亦被收录于 objc中国。 很少有人听过 DTrace,它是隐藏在 OS 中的小宝藏。DTrace 是强大的 debug 工具 …">
<!-- http://t.co/dKP3o1e -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/atom.xml" rel="alternate" title="Migrant" type="application/atom+xml">
<link rel="canonical" href="http://objcio.com/">
<link href="/favicon.png" rel="shortcut icon">
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<link href="/stylesheets/font-awesome.min.css" media="screen, projection" rel="stylesheet" type="text/css">
<!--[if lt IE 9]><script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400italic,400,700' rel='stylesheet' type='text/css'>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
<link href="http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
</head>
<body>
<div class="container">
<div class="left-col">
<div class="intrude-less">
<header id="header" class="inner"><div class="profilepic">
<script src="/javascripts/md5.js"></script>
<script type="text/javascript">
$(function(){
$('.profilepic').append("<img src='http://www.gravatar.com/avatar/" + MD5("tomigrant@gmail.com") + "?s=160' alt='Profile Picture' style='width: 160px;' />");
});
</script>
</div>
<hgroup>
<h1><a href="/">Migrant</a></h1>
<h2>橱窗里的荷兰赌徒</h2>
</hgroup>
<nav id="main-nav"><ul class="main-navigation">
<li><a href="/">Blog</a></li>
<li><a href="/blog/archives">Archives</a></li>
</ul>
</nav>
<nav id="sub-nav">
<div class="social">
<a class="weibo" href="http://www.weibo.com/2168385817" title="Weibo">Weibo</a>
<a class="rss" href="/atom.xml" title="RSS">RSS</a>
</div>
</nav>
</header>
</div>
</div>
<div class="mid-col">
<div class="mid-col-container">
<div id="content" class="inner">
<div itemscope itemtype="http://schema.org/Blog">
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2015-01-06T12:10:00+08:00" data-updated="true" itemprop="datePublished">Jan 6<span>th</span>, 2015</time></div>
<div class="tags">
<a class='category' href='/blog/categories/ios/'>iOS</a>, <a class='category' href='/blog/categories/fan-yi/'>翻译</a>
</div>
<span class="comments"><a href="/blog/2015/01/06/dtrace/#disqus_thread">Comments</a></span>
</div>
<h1 class="title" itemprop="name"><a href="/blog/2015/01/06/dtrace/" itemprop="url">DTrace</a></h1>
<div class="entry-content" itemprop="articleBody">
<p>本文由 <a href="http://objcio.com"><strong>Migrant</strong></a> 翻译自 <a href="http://www.objc.io/issue-19/dtrace.html">DTrace</a>,感谢 <a href="http://onevcat.com/">onevcat</a> 校对,转载请注明出处。本文亦被收录于 <a href="http://objccn.io/">objc中国</a>。</p>
<p>很少有人听过 DTrace,它是隐藏在 OS 中的小宝藏。DTrace 是强大的 debug 工具 – 因为它拥有极其灵活的特性,并且因为与其它工具差异很大而可能相对不那么有名。</p>
<p>许多时候你的 app 的真正的用户或测试人员会看到一些意外的行为。DTrace 可以让你无需重启 app 就能够在生产版本上回答关于 app 的任何问题。</p>
<a href="/blog/2015/01/06/dtrace/" class="more-link">Read on →</a>
</div>
</article>
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2014-11-26T10:03:00+08:00" data-updated="true" itemprop="datePublished">Nov 26<span>th</span>, 2014</time></div>
<div class="tags">
<a class='category' href='/blog/categories/ios/'>iOS</a>, <a class='category' href='/blog/categories/fan-yi/'>翻译</a>
</div>
<span class="comments"><a href="/blog/2014/11/26/metal/#disqus_thread">Comments</a></span>
</div>
<h1 class="title" itemprop="name"><a href="/blog/2014/11/26/metal/" itemprop="url">Metal</a></h1>
<div class="entry-content" itemprop="articleBody">
<p>本文由 <a href="http://objcio.com"><strong>Migrant</strong></a> 翻译自 <a href="http://www.objc.io/issue-18/metal.html">Metal</a>,感谢 <a href="http://onevcat.com/">onevcat</a> 校对,转载请注明出处。本文亦被收录于 <a href="http://objccn.io/">objc中国</a>。</p>
<blockquote><p>Mental 框架支持 GPU 加速高级 3D 图像渲染,以及数据并行计算工作。Mental 提供了先进合理的 API,它不仅为图形的组织、处理和呈现,也为计算命令以及为这些命令相关的数据和资源的管理,提供了细粒度和底层的控制。Mental 的主要目的是最小化 GPU 工作时 CPU 所要的消耗。</p></blockquote>
<p>– <a href="https://developer.apple.com/library/ios/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40014221-CH1-SW1">Metal Programming Guide</a></p>
<p>Mental 是针对 iPhone 和 iPad 中 GPU 编程的高度优化的框架。其名字来源是因为 Metal 是 iOS 平台中最底层的图形框架 (意指 “最接近硬件”)。</p>
<p>该框架被设计用来实现两个目标: 3D 图形渲染和并行计算。这两者有很多共同点。它们都在数量庞大的数据上并行运行特殊的代码,并可以在 <a href="https://en.wikipedia.org/wiki/Graphics_processing_unit">GPU</a>. 上执行。</p>
<a href="/blog/2014/11/26/metal/" class="more-link">Read on →</a>
</div>
</article>
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2014-05-21T11:25:00+08:00" data-updated="true" itemprop="datePublished">May 21<span>st</span>, 2014</time></div>
<div class="tags">
<a class='category' href='/blog/categories/ios/'>iOS</a>, <a class='category' href='/blog/categories/fan-yi/'>翻译</a>
</div>
<span class="comments"><a href="/blog/2014/05/21/the-complete-tutorial-on-ios-slash-iphone-custom-url-schemes/#disqus_thread">Comments</a></span>
</div>
<h1 class="title" itemprop="name"><a href="/blog/2014/05/21/the-complete-tutorial-on-ios-slash-iphone-custom-url-schemes/" itemprop="url">自定义 URL Scheme 完全指南</a></h1>
<div class="entry-content" itemprop="articleBody">
<p>本文由 <a href="http://objcio.com"><strong>Migrant</strong></a> 翻译自 <a href="http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html">The Complete Tutorial on iOS/iPhone Custom URL Schemes</a>,转载请注明出处。</p>
<p><strong>注意</strong>: <em>自从自定义 URL 的引入,本文始终是我博客中阅读量最大的文章。虽然大多数都相同,但仍然有一些细微差别的变化。本文是原帖的重写版,更新为最新的 iOS 和 Xcode 版本。</em></p>
<p>iPhone / iOS SDK 最酷的特性之一就是应用将其自身”绑定”到一个自定义 URL scheme 上,该 scheme 用于从浏览器或其他应用中启动本应用。</p>
<h2>注册自定义 URL Scheme</h2>
<p>注册自定义 URL Scheme 的第一步是创建 URL Scheme — 在 Xcode Project Navigator 中找到并点击工程 info.plist 文件。当该文件显示在右边窗口,在列表上点击鼠标右键,选择 <em>Add Row</em>:</p>
<p>向下滚动弹出的列表并选择 <em>URL types</em>。</p>
<p><img src="/images/posts/2014-05-21-the-complete-tutorial-on-ios-slash-iphone-custom-url-schemes-01.gif" alt="iOS Custom URL Scheme" /></p>
<p>点击左边剪头打开列表,可以看到 <em>Item 0</em>,一个字典实体。展开 <em>Item 0</em>,可以看到 <em>URL Identifier</em>,一个字符串对象。该字符串是你自定义的 URL scheme 的名字。建议采用反转域名的方法保证该名字的唯一性,比如 <em>com.yourCompany.yourApp</em>。</p>
<p><img src="/images/posts/2014-05-21-the-complete-tutorial-on-ios-slash-iphone-custom-url-schemes-02.gif" alt="urlScheme2a" /></p>
<p>点击 <em>Item 0</em> 新增一行,从下拉列表中选择 <em>URL Schemes</em>,敲击键盘回车键完成插入。</p>
<p><img src="/images/posts/2014-05-21-the-complete-tutorial-on-ios-slash-iphone-custom-url-schemes-03.gif" alt="iOS Custom URL Scheme" /></p>
<p>注意 URL Schemes 是一个数组,允许应用定义多个 URL schemes。</p>
<p><img src="/images/posts/2014-05-21-the-complete-tutorial-on-ios-slash-iphone-custom-url-schemes-04.gif" alt="iOS Custom URL Scheme" /></p>
<p>展开该数据并点击 <em>Item 0</em>。你将在这里定义自定义 URL scheme 的名字。只需要名字,不要在后面追加 :// — 比如,如果你输入 iOSDevApp,你的自定义 url 就是 iOSDevApp://</p>
<p><img src="/images/posts/2014-05-21-the-complete-tutorial-on-ios-slash-iphone-custom-url-schemes-05.gif" alt="iOS Custom URL Scheme" /></p>
<p>此时,整个定义如下图:</p>
<p><img src="/images/posts/2014-05-21-the-complete-tutorial-on-ios-slash-iphone-custom-url-schemes-06.gif" alt="iOS Custom URL Scheme" /></p>
<p>虽然我赞同 Xcode 使用描述性的名字的目的,不过看到创建的实际的 key 也是非常有用的。这里有一个方便的技巧,右键点击 plist 并选择 <em>Show Raw Keys/Values</em>,就能看到以下效果:</p>
<p><img src="/images/posts/2014-05-21-the-complete-tutorial-on-ios-slash-iphone-custom-url-schemes-07.png" alt="iOS Custom URL Scheme" /></p>
<p>还有另一种有用的输出格式,XML,因为可以非常容易的看到字典和原始数组及其包括的实体的结构。点击 plist 并选择 <em>Open As – Source Code</em>:</p>
<p><img src="/images/posts/2014-05-21-the-complete-tutorial-on-ios-slash-iphone-custom-url-schemes-08.gif" alt="iPhone Custom URL Scheme" /></p>
<a href="/blog/2014/05/21/the-complete-tutorial-on-ios-slash-iphone-custom-url-schemes/" class="more-link">Read on →</a>
</div>
</article>
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2014-05-01T22:36:00+08:00" data-updated="true" itemprop="datePublished">May 1<span>st</span>, 2014</time></div>
<div class="tags">
<a class='category' href='/blog/categories/ibeacon/'>iBeacon</a>, <a class='category' href='/blog/categories/ios/'>iOS</a>, <a class='category' href='/blog/categories/fan-yi/'>翻译</a>
</div>
<span class="comments"><a href="/blog/2014/05/01/can-you-smell-the-ibeacon/#disqus_thread">Comments</a></span>
</div>
<h1 class="title" itemprop="name"><a href="/blog/2014/05/01/can-you-smell-the-ibeacon/" itemprop="url">iBeacon 来了</a></h1>
<div class="entry-content" itemprop="articleBody">
<p>本文由 <a href="http://objcio.com"><strong>Migrant</strong></a> 翻译自 <a href="http://www.cocoanetics.com/2013/11/can-you-smell-the-ibeacon/">Can you Smell the iBeacon?</a>,转载请注明出处。</p>
<p>虽然我们还未看到任何实际生活中的使用案例,但 iBeacon 绝对是 iOS 7 带来的最热门的新话题之一。</p>
<p>上周我收到了我的 <a href="https://preorder.estimote.com/">Developer Preview Kit from Estimote</a>,为了将其收入我正在写作的新书中,我开始研究 iBeacon。下面是我的发现。</p>
<p>为了理解两种操作模式的不同之处,有两个词你应该知道:</p>
<ul>
<li><strong>Monitoring</strong> – 涉及小功率区域监测,接收 didEnterRegion: 和 didExitRegion: 代理消息。</li>
<li><strong>Ranging</strong> – 意味着大功率活动,此时你能从各个 iBeacon 收到信号强度并能够估计此刻与它们的距离。</li>
</ul>
<p>iOS 7 之前苹果给我们提供了监测设备将要进入或离开某一个特定区域的能力,其核心是 <code>CLRegion</code>。该技术围绕着地理位置和进入或退出该位置时将要发生的事情。更好的是,如果你在 info.plist 中指定了接收后台位置更新,那么系统可以在区域边界处激活你的应用。</p>
<p>iOS 7 增加了继承自 CLRegion 的 <code>CLBeaconRegion</code>。只要有 iBeacon 被 iOS 检测到,即使信号可能很弱,你就被定义为位于区域之内。这让测试过程令人发疯,因为即使我把我所有的 Estmote beacons 用铝箔包裹起来, iOS 仍然认为我位于该区域内。</p>
<p>一个 iBeacon 通过 3 个值被识别: proximityUUID, Major 和 Minor。第一个是 UUID,后两者是两个 16 位二进制整数。你可以构建 3 个级别的 CLBeaconRegion: 只有 UUID,UUID + Major,UUID + Major + Minor。例如你可能想用一个 UUID 对应整个公司,Major 对应各个店铺。Minor 则可以用来指定每个店铺中的各个货架。</p>
<a href="/blog/2014/05/01/can-you-smell-the-ibeacon/" class="more-link">Read on →</a>
</div>
</article>
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2014-04-25T22:25:00+08:00" data-updated="true" itemprop="datePublished">Apr 25<span>th</span>, 2014</time></div>
<div class="tags">
<a class='category' href='/blog/categories/ios/'>iOS</a>, <a class='category' href='/blog/categories/objc-dot-io/'>objc.io</a>, <a class='category' href='/blog/categories/fan-yi/'>翻译</a>
</div>
<span class="comments"><a href="/blog/2014/04/25/mastering-the-icloud-document-store/#disqus_thread">Comments</a></span>
</div>
<h1 class="title" itemprop="name"><a href="/blog/2014/04/25/mastering-the-icloud-document-store/" itemprop="url">精通iCloud文档存储</a></h1>
<div class="entry-content" itemprop="articleBody">
<p>本文由 <a href="http://objcio.com"><strong>Migrant</strong></a> 翻译自 <a href="http://www.objc.io/issue-10/icloud-document-store.html">Mastering the iCloud Document Store</a>,转载请注明出处。</p>
<p>即便在推出 3 年后,iCloud 文档存储依然是一个充满神秘、误解和抱怨的话题。iCloud 同步经常被批评不可靠且速度慢。虽然在 iCloud 的早期有一些严重的 bug,开发者们还是不得不学习有关文件同步的课程。文件同步事关重大,为应用开发带来了新方向 — 一个经常被低估的方向,比如进行同步服务相关的合作时,对于处理文件异步更改的需要。</p>
<p>本文会介绍几个创建支持 iCloud 的应用时可能会遇到的一些绊脚石。因为本文只会给出一些粗略的概述,所以如果你对 iCloud 文档存储还不熟悉,我们强烈建议你先阅读 <a href="https://developer.apple.com/library/ios/documentation/General/Conceptual/iCloudDesignGuide/Chapters/DesigningForDocumentsIniCloud.html">Apple iCloud companion guide</a>。</p>
<a href="/blog/2014/04/25/mastering-the-icloud-document-store/" class="more-link">Read on →</a>
</div>
</article>
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2014-03-10T10:27:00+08:00" data-updated="true" itemprop="datePublished">Mar 10<span>th</span>, 2014</time></div>
<div class="tags">
<a class='category' href='/blog/categories/ios/'>iOS</a>, <a class='category' href='/blog/categories/objc-dot-io/'>objc.io</a>, <a class='category' href='/blog/categories/fan-yi/'>翻译</a>
</div>
<span class="comments"><a href="/blog/2014/03/10/custom-controls/#disqus_thread">Comments</a></span>
</div>
<h1 class="title" itemprop="name"><a href="/blog/2014/03/10/custom-controls/" itemprop="url">自定义控件</a></h1>
<div class="entry-content" itemprop="articleBody">
<p>本文由 <a href="http://objcio.com"><strong>Migrant</strong></a> 翻译自 <a href="http://www.objc.io/issue-3/custom-controls.html">Custom Controls</a>,转载请注明出处。</p>
<p>本文将讨论一些自定义视图和控件的诀窍和技巧。我们先对UIKit已经提供给我们的控件做一个概览,介绍一些渲染技巧。随后我们会深入到视图和它们的所有者之间的通信策略,并简略探讨辅助功能,本地化和测试。</p>
<a href="/blog/2014/03/10/custom-controls/" class="more-link">Read on →</a>
</div>
</article>
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2014-02-14T11:39:00+08:00" data-updated="true" itemprop="datePublished">Feb 14<span>th</span>, 2014</time></div>
<div class="tags">
<a class='category' href='/blog/categories/ios/'>iOS</a>, <a class='category' href='/blog/categories/fan-yi/'>翻译</a>
</div>
<span class="comments"><a href="/blog/2014/02/14/correct-way-of-defining-constants-in-objective-c/#disqus_thread">Comments</a></span>
</div>
<h1 class="title" itemprop="name"><a href="/blog/2014/02/14/correct-way-of-defining-constants-in-objective-c/" itemprop="url">正确定义Objective-C常量</a></h1>
<div class="entry-content" itemprop="articleBody">
<p>本文由 <a href="http://migrant.github.io/"><strong>Migrant</strong></a> 翻译自 <a href="http://walkingsmarts.com/correct-way-of-defining-constants-in-objective-c/">Correct Way of Defining Constants in Objective-C</a>,转载请注明出处。</p>
<p>本文只是一个关于如何在Cocoa代码中定义常量的书签贴,答案来自于<a href="http://stackoverflow.com/questions/538996/constants-in-objective-c">stackoverflow.com的这个问题</a>。这里为那些懒人提供了一些简短的介绍和帖子本身。你可能读遍了苹果开发者文档,知道一些特定的方法参数只能接受定义为常量的枚举值列表。比如事件类型标记(<code>NSKeyUpMask</code>,<code>NSKeyDownMask</code>,等等),persistent store coordinator的存储类型(<code>NSSQLiteStoreType</code>,<code>NSBinaryStoreType</code>和<code>NSInMemoryStoreType</code>),当然还有很多其他的。所有的这些归结为几行代码。实际上定义常量的时候代码行数是你想要的常量的两倍。步骤为:首先,创建<code>Constants.h</code>和<code>Constants.m</code>文件用来存放我们的常量。在<code>Constants.h</code>中,指定常量名字,将常量声明为一个指向<code>NSString</code>对象的指针:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='objc'><span class='line'><span class="c1">// Constants.h</span>
</span><span class='line'><span class="k">extern</span> <span class="n">NSString</span> <span class="o">*</span> <span class="k">const</span> <span class="n">MyOwnConstant</span><span class="p">;</span>
</span><span class='line'><span class="k">extern</span> <span class="n">NSString</span> <span class="o">*</span> <span class="k">const</span> <span class="n">YetAnotherConstant</span><span class="p">;</span>
</span></code></pre></td></tr></table></div></figure>
<p>最后,在<code>Constants.m</code>中通过赋值定义常量:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='objc'><span class='line'><span class="c1">// Constants.m</span>
</span><span class='line'><span class="n">NSString</span> <span class="o">*</span> <span class="k">const</span> <span class="n">MyOwnConstant</span> <span class="o">=</span> <span class="s">@"myOwnConstant"</span><span class="p">;</span>
</span><span class='line'><span class="n">NSString</span> <span class="o">*</span> <span class="k">const</span> <span class="n">YetAnotherConstant</span> <span class="o">=</span> <span class="s">@"yetAnotherConstant"</span><span class="p">;</span>
</span></code></pre></td></tr></table></div></figure>
<p>现在你所需要做的只是引入<code>Constants.h</code>文件到你工程的预编译头文件。如果你有点小聪明,可能脑中会有两个问题。第一个问题或许是:在能够使用<code>#define</code>的情况下为什么要使用这种方法?这是个非常有意义的问题。答案很简单(但是在读到<a href="http://stackoverflow.com/questions/538996/constants-in-objective-c/539191#539191">这个答案</a>之前还不是很明显) — 使用这种方法你可以进行指针比较(<code>@"myString" == MyConstant</code>)而不是字符串比较(<code>[@"myString" isEqualToString:MyConstant]</code>)。前者非常非常快。第二个问题应该是为什么应该完全使用常量。又一个有意义的问题。你可以在每个使用常量的地方使用常量对应的值。但是有两个”但是”。第一,始终有人的因素。你很容易输入错字符串,而编译器并不会抱怨你的语法。但如果使用常量,它就会在你输入错常量名称的时候给予你警告。还有(第二个”但是”),XCode会尽最大努力的帮助我们自动完成代码,这些常量也不例外,因此方法会变得非常方便。Happy coding!</p>
</div>
</article>
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2014-01-20T17:41:00+08:00" data-updated="true" itemprop="datePublished">Jan 20<span>th</span>, 2014</time></div>
<div class="tags">
<a class='category' href='/blog/categories/ios/'>iOS</a>, <a class='category' href='/blog/categories/objc-dot-io/'>objc.io</a>, <a class='category' href='/blog/categories/fan-yi/'>翻译</a>
</div>
<span class="comments"><a href="/blog/2014/01/20/the-foundation-collection-classes/#disqus_thread">Comments</a></span>
</div>
<h1 class="title" itemprop="name"><a href="/blog/2014/01/20/the-foundation-collection-classes/" itemprop="url">基础集合类</a></h1>
<div class="entry-content" itemprop="articleBody">
<p>本文由 <a href="http://migrant.github.io/"><strong>Migrant</strong></a> 翻译自 <a href="http://www.objc.io/issue-7/collections.html">The Foundation Collection Classes</a>,转载请注明出处。</p>
<h2>NSArray, NSSet, NSOrderedSet 和 NSDictionary</h2>
<p>基础集合类是每一个Mac/iOS应用的基本组成部分。在本文中,我们将对”老类”(<code>NSArray</code>, <code>NSSet</code>)和”新类”(<code>NSMapTable</code>, <code>NSHashTable</code>, <code>NSPointerArray</code>)进行一个深入的研究,探索每一个的效率细节,并讨论其使用场景。</p>
<p>作者提示:本文包含一些参照结果,但它们并不意味着绝对精确,也没有进行多个、复杂的测试。这些结果的目的是给出一个快速和主要的运行时统计。所有的测试基于iPhone 5s,使用Xcode 5.1b1和iOS 7.1b1,64位的程序。编译选项设置为-Ofast的发布构建。Vectorize loops和unroll loops(默认设置)均设置为关闭。</p>
<a href="/blog/2014/01/20/the-foundation-collection-classes/" class="more-link">Read on →</a>
</div>
</article>
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2013-12-04T13:36:00+08:00" data-updated="true" itemprop="datePublished">Dec 4<span>th</span>, 2013</time></div>
<div class="tags">
<a class='category' href='/blog/categories/ios/'>iOS</a>, <a class='category' href='/blog/categories/fan-yi/'>翻译</a>
</div>
<span class="comments"><a href="/blog/2013/12/04/understanding-frame/#disqus_thread">Comments</a></span>
</div>
<h1 class="title" itemprop="name"><a href="/blog/2013/12/04/understanding-frame/" itemprop="url">理解Frame</a></h1>
<div class="entry-content" itemprop="articleBody">
<p>本文由 <a href="http://migrant.github.io/"><strong>Migrant</strong></a> 翻译自 <a href="http://macoscope.com/blog/understanding-frame/">Understanding Frame</a>,转载请注明出处。</p>
<p>Frame是布局的核心。每个开发者都使用frame定位和改变<code>UIView</code>和<code>CALayer</code>的大小。在本文中我将把焦点集中在<code>CALayer</code>上,因为它是<code>UIView</code>的底层实现,<code>view.frame</code>简单的返回了<code>view.layer.frame</code>。此外,我不会讨论<code>setFrame:</code>方法。虽然看起来范围十分有限,但实际上有许多有趣的事情在平凡又古老的<code>frame</code> getter方法中发生。</p>
<a href="/blog/2013/12/04/understanding-frame/" class="more-link">Read on →</a>
</div>
</article>
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2013-11-30T22:45:00+08:00" data-updated="true" itemprop="datePublished">Nov 30<span>th</span>, 2013</time></div>
<div class="tags">
<a class='category' href='/blog/categories/ios/'>iOS</a>, <a class='category' href='/blog/categories/raywenderlich/'>raywenderlich</a>, <a class='category' href='/blog/categories/fan-yi/'>翻译</a>
</div>
<span class="comments"><a href="/blog/2013/11/30/creating-a-static-library-in-ios-tutorial/#disqus_thread">Comments</a></span>
</div>
<h1 class="title" itemprop="name"><a href="/blog/2013/11/30/creating-a-static-library-in-ios-tutorial/" itemprop="url">在iOS中创建静态库</a></h1>
<div class="entry-content" itemprop="articleBody">
<p>本文由 <a href="http://migrant.github.io/"><strong>Migrant</strong></a> 翻译自 <a href="http://www.raywenderlich.com/41377/creating-a-static-library-in-ios-tutorial">Creating a Static Library in iOS Tutorial</a>,转载请注明出处。</p>
<p><img class="right" src="/images/posts/2013-11-30-creating-a-static-library-in-ios-tutorial-00.jpg" title="Create a static library in iOS!" ></p>
<p>如果你作为iOS开发者已经有一段时间,可能会有一套属于自己的类和工具函数,它们在你的大多数项目中被重用。</p>
<p>重用代码的最简单方法是简单的 <em>拷贝/粘贴</em> 源文件。然而,这种方法很快就会成为维护时的噩梦。因为每个应用都有自己的一份代码副本,你很难在修复bug或者升级时保证所有副本的同步。</p>
<p>这就是静态库要拯救你的。一个静态库是若干个类,函数,定义和资源的包装,你可以将其打包并很容易的在项目之间共享。</p>
<p>在本教程中,你将用两种方法亲手创建你自己的通用静态库。</p>
<a href="/blog/2013/11/30/creating-a-static-library-in-ios-tutorial/" class="more-link">Read on →</a>
</div>
</article>
</div>
<nav id="pagenavi">
<a href="/blog/page/2/" class="next">Next</a>
<div class="center"><a href="/blog/archives">Blog Archives</a></div>
</nav></div>
</div>
<footer id="footer" class="inner"><p>
Copyright © 2015 - Migrant -
<span class="credit">Powered by <a href="http://octopress.org">Octopress</a></span>
</p>
Design credit: <a href="http://shashankmehta.in/archive/2012/greyshade.html">Shashank Mehta</a></footer>
<script src="/javascripts/slash.js"></script>
<script src="/javascripts/jquery.fancybox.pack.js"></script>
<script type="text/javascript">
(function($){
$('.fancybox').fancybox();
})(jQuery);
</script> <!-- Delete or comment this line to disable Fancybox -->
<script type="text/javascript">
var disqus_shortname = 'objcio';
var disqus_script = 'count.js';
(function () {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/' + disqus_script;
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
}());
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-44039159-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</div>
</div>
</body>
</html>