Preface |
|
xv | |
Part I Language |
|
|
1 The Architecture of Swift |
|
|
3 | (22) |
|
|
3 | (1) |
|
|
4 | (2) |
|
Three Flavors of Object Type |
|
|
6 | (1) |
|
|
6 | (2) |
|
|
8 | (1) |
|
The Structure of a Swift File |
|
|
9 | (3) |
|
|
12 | (1) |
|
|
13 | (1) |
|
|
13 | (1) |
|
|
14 | (1) |
|
|
15 | (2) |
|
|
17 | (2) |
|
|
19 | (1) |
|
|
20 | (2) |
|
|
22 | (3) |
|
|
25 | (46) |
|
Function Parameters and Return Value |
|
|
25 | (5) |
|
Void Return Type and Parameters |
|
|
29 | (1) |
|
|
30 | (1) |
|
|
30 | (2) |
|
|
32 | (1) |
|
|
33 | (1) |
|
|
34 | (1) |
|
|
35 | (1) |
|
|
36 | (4) |
|
Calling Objective-C with Modifiable Parameters |
|
|
37 | (1) |
|
Called by Objective-C with Modifiable Parameters |
|
|
38 | (1) |
|
Reference Type Modifiable Parameters |
|
|
39 | (1) |
|
|
40 | (1) |
|
|
40 | (1) |
|
|
41 | (3) |
|
|
44 | (6) |
|
Using Anonymous Functions Inline |
|
|
45 | (1) |
|
Anonymous Function Abbreviated Syntax |
|
|
46 | (4) |
|
|
50 | (1) |
|
|
51 | (11) |
|
How Closures Improve Code |
|
|
53 | (1) |
|
Function Returning Function |
|
|
54 | (3) |
|
Closure Setting a Captured Variable |
|
|
57 | (1) |
|
Closure Preserving Captured Environment |
|
|
58 | (1) |
|
|
59 | (1) |
|
|
60 | (2) |
|
|
62 | (1) |
|
Function References and Selectors |
|
|
63 | (8) |
|
|
65 | (2) |
|
|
67 | (4) |
|
3 Variables and Simple Types |
|
|
71 | (54) |
|
Variable Scope and Lifetime |
|
|
71 | (2) |
|
|
73 | (4) |
|
Computed Variable Initialization |
|
|
77 | (1) |
|
|
78 | (4) |
|
|
79 | (2) |
|
|
81 | (1) |
|
|
82 | (1) |
|
|
83 | (2) |
|
|
84 | (1) |
|
Lazy Initialization of Instance Properties |
|
|
85 | (1) |
|
|
85 | (40) |
|
|
85 | (3) |
|
|
88 | (8) |
|
|
96 | (6) |
|
Character and String Index |
|
|
102 | (4) |
|
|
106 | (2) |
|
|
108 | (3) |
|
|
111 | (14) |
|
|
125 | (144) |
|
Object Type Declarations and Features |
|
|
125 | (17) |
|
|
127 | (6) |
|
|
133 | (3) |
|
|
136 | (3) |
|
|
139 | (2) |
|
|
141 | (1) |
|
|
142 | (11) |
|
|
143 | (2) |
|
|
145 | (2) |
|
|
147 | (1) |
|
|
148 | (1) |
|
|
149 | (1) |
|
|
150 | (2) |
|
|
152 | (1) |
|
|
153 | (3) |
|
|
153 | (1) |
|
|
154 | (1) |
|
|
155 | (1) |
|
|
156 | (22) |
|
Value Types and Reference Types |
|
|
157 | (5) |
|
|
162 | (6) |
|
|
168 | (8) |
|
|
176 | (1) |
|
|
176 | (1) |
|
|
177 | (1) |
|
|
178 | (4) |
|
|
182 | (5) |
|
|
183 | (1) |
|
Type Testing and Casting Down Safely |
|
|
183 | (2) |
|
Type Testing and Casting Optionals |
|
|
185 | (1) |
|
|
186 | (1) |
|
|
187 | (6) |
|
|
187 | (1) |
|
|
187 | (4) |
|
|
191 | (1) |
|
Summary of Type Terminology |
|
|
192 | (1) |
|
|
192 | (1) |
|
|
193 | (12) |
|
|
194 | (1) |
|
Adopting a Library Protocol |
|
|
195 | (2) |
|
Protocol Type Testing and Casting |
|
|
197 | (1) |
|
|
197 | (1) |
|
|
198 | (1) |
|
|
199 | (1) |
|
Optional Protocol Members |
|
|
200 | (2) |
|
Implicitly Required Initializers |
|
|
202 | (2) |
|
|
204 | (1) |
|
|
205 | (15) |
|
|
208 | (2) |
|
|
210 | (2) |
|
|
212 | (1) |
|
Generic Types and Covariance |
|
|
213 | (2) |
|
|
215 | (2) |
|
|
217 | (3) |
|
|
220 | (7) |
|
|
222 | (3) |
|
|
225 | (2) |
|
|
227 | (5) |
|
|
227 | (2) |
|
|
229 | (2) |
|
|
231 | (1) |
|
|
232 | (37) |
|
|
232 | (19) |
|
|
251 | (7) |
|
|
258 | (5) |
|
OrderedSet and OrderedDictionary |
|
|
263 | (6) |
|
|
269 | (74) |
|
|
269 | (36) |
|
|
270 | (12) |
|
|
282 | (6) |
|
|
288 | (17) |
|
|
305 | (4) |
|
|
306 | (2) |
|
|
308 | (1) |
|
|
309 | (1) |
|
|
309 | (1) |
|
|
310 | (3) |
|
|
313 | (10) |
|
Memory Management of Reference Types |
|
|
314 | (7) |
|
Exclusive Access to Value Types |
|
|
321 | (2) |
|
Miscellaneous Swift Language Features |
|
|
323 | (20) |
|
Synthesized Protocol Implementations |
|
|
323 | (3) |
|
|
326 | (3) |
|
|
329 | (1) |
|
|
330 | (2) |
|
|
332 | (5) |
|
Custom String Interpolation |
|
|
337 | (2) |
|
|
339 | (2) |
|
|
341 | (1) |
|
|
341 | (2) |
|
|
343 | (52) |
|
|
344 | (9) |
|
|
344 | (1) |
|
|
345 | (2) |
|
|
347 | (6) |
|
Structured Concurrency Syntax |
|
|
353 | (3) |
|
|
354 | (1) |
|
|
355 | (1) |
|
|
356 | (1) |
|
Wrapping a Completion Handler |
|
|
357 | (4) |
|
Multiple Concurrent Tasks |
|
|
361 | (6) |
|
|
362 | (1) |
|
|
363 | (4) |
|
|
367 | (3) |
|
Built-in Asynchronous Sequences |
|
|
368 | (1) |
|
Making an Asynchronous Sequence |
|
|
369 | (1) |
|
Asynchronous Sequence Methods |
|
|
370 | (1) |
|
|
370 | (4) |
|
|
371 | (1) |
|
|
372 | (1) |
|
|
372 | (2) |
|
|
374 | (3) |
|
Implicit Context Switching |
|
|
374 | (1) |
|
Explicit Context Switching |
|
|
375 | (2) |
|
|
377 | (9) |
|
|
377 | (1) |
|
|
378 | (1) |
|
|
378 | (1) |
|
|
379 | (1) |
|
|
380 | (6) |
|
|
386 | (4) |
|
|
386 | (1) |
|
|
387 | (1) |
|
|
388 | (1) |
|
|
389 | (1) |
|
|
390 | (5) |
Part II IDE |
|
|
7 Anatomy of an Xcode Project |
|
|
395 | (42) |
|
|
395 | (2) |
|
|
397 | (11) |
|
|
399 | (5) |
|
|
404 | (1) |
|
|
405 | (3) |
|
Project File and Dependents |
|
|
408 | (3) |
|
Contents of the Project Folder |
|
|
409 | (1) |
|
|
410 | (1) |
|
|
411 | (7) |
|
|
411 | (2) |
|
|
413 | (1) |
|
|
414 | (2) |
|
|
416 | (2) |
|
From Project to Built App |
|
|
418 | (11) |
|
|
420 | (1) |
|
|
420 | (1) |
|
|
421 | (1) |
|
|
421 | (2) |
|
|
423 | (1) |
|
|
424 | (1) |
|
|
425 | (4) |
|
|
429 | (5) |
|
|
429 | (2) |
|
|
431 | (2) |
|
|
433 | (1) |
|
Renaming Parts of a Project |
|
|
434 | (3) |
|
|
437 | (34) |
|
|
438 | (6) |
|
|
439 | (3) |
|
|
442 | (1) |
|
|
443 | (1) |
|
|
444 | (4) |
|
Loading a View Controller Nib |
|
|
445 | (1) |
|
|
446 | (1) |
|
Loading a View Nib Manually |
|
|
447 | (1) |
|
|
448 | (18) |
|
|
449 | (1) |
|
|
450 | (4) |
|
Automatically Configured Nibs |
|
|
454 | (1) |
|
|
455 | (2) |
|
|
457 | (1) |
|
More Ways to Create Outlets |
|
|
457 | (3) |
|
|
460 | (1) |
|
|
461 | (2) |
|
More Ways to Create Actions |
|
|
463 | (1) |
|
|
464 | (1) |
|
Connections Between Nibs - Not! |
|
|
465 | (1) |
|
Additional Configuration of Nib-Based Instances |
|
|
466 | (5) |
|
|
471 | (16) |
|
|
471 | (2) |
|
Class Documentation Pages |
|
|
473 | (3) |
|
|
476 | (3) |
|
Documenting Frameworks and Packages |
|
|
479 | (3) |
|
|
482 | (1) |
|
|
483 | (1) |
|
|
484 | (1) |
|
|
484 | (3) |
|
10 Life Cycle of a Project |
|
|
487 | (84) |
|
Environmental Dependencies |
|
|
487 | (8) |
|
|
488 | (1) |
|
|
489 | (1) |
|
Permissible Runtime Environment |
|
|
490 | (1) |
|
|
491 | (1) |
|
|
492 | (2) |
|
Arguments and Environment Variables |
|
|
494 | (1) |
|
|
495 | (3) |
|
Editing and Navigating Your Code |
|
|
498 | (12) |
|
|
499 | (1) |
|
|
500 | (1) |
|
Code Completion and Placeholders |
|
|
501 | (1) |
|
|
502 | (1) |
|
Refactoring and Code Actions |
|
|
503 | (2) |
|
Fix-it and Live Syntax Checking |
|
|
505 | (1) |
|
|
506 | (3) |
|
|
509 | (1) |
|
|
510 | (2) |
|
|
512 | (12) |
|
|
512 | (4) |
|
|
516 | (8) |
|
|
524 | (12) |
|
|
527 | (4) |
|
|
531 | (2) |
|
|
533 | (2) |
|
|
535 | (1) |
|
|
536 | (1) |
|
|
537 | (6) |
|
Obtaining a Developer Program Membership |
|
|
537 | (1) |
|
|
538 | (1) |
|
|
539 | (2) |
|
|
541 | (1) |
|
|
542 | (1) |
|
Managing Development Certificates and Devices |
|
|
543 | (1) |
|
|
543 | (5) |
|
|
544 | (1) |
|
|
544 | (2) |
|
|
546 | (2) |
|
|
548 | (6) |
|
Creating Localized Content |
|
|
548 | (5) |
|
|
553 | (1) |
|
|
554 | (17) |
|
|
555 | (1) |
|
The Distribution Certificate |
|
|
556 | (1) |
|
|
557 | (1) |
|
|
558 | (2) |
|
|
560 | (2) |
|
Screenshots and Video Previews |
|
|
562 | (1) |
|
|
563 | (2) |
|
Submission to the App Store |
|
|
565 | (6) |
Part III Cocoa |
|
|
|
571 | (48) |
|
|
571 | (3) |
|
Categories and Extensions |
|
|
574 | (2) |
|
How Swift Uses Extensions |
|
|
574 | (1) |
|
|
574 | (1) |
|
How Cocoa Uses Categories |
|
|
575 | (1) |
|
|
576 | (4) |
|
|
577 | (3) |
|
|
580 | (1) |
|
|
580 | (29) |
|
|
581 | (2) |
|
|
583 | (1) |
|
|
584 | (3) |
|
|
587 | (3) |
|
|
590 | (2) |
|
|
592 | (1) |
|
|
593 | (1) |
|
NSMeasurement and Friends |
|
|
594 | (1) |
|
Equality, Hashability, and Comparison |
|
|
595 | (3) |
|
NSArray and NSMutableArray |
|
|
598 | (2) |
|
NSDictionary and NSMutableDictionary |
|
|
600 | (1) |
|
|
601 | (1) |
|
|
602 | (1) |
|
|
603 | (1) |
|
|
603 | (1) |
|
|
604 | (1) |
|
|
605 | (4) |
|
Accessors, Properties, and Key-Value Coding |
|
|
609 | (7) |
|
|
610 | (1) |
|
|
611 | (1) |
|
|
612 | (1) |
|
|
613 | (1) |
|
|
614 | (1) |
|
|
615 | (1) |
|
The Secret Life of NSObject |
|
|
616 | (3) |
|
|
619 | (34) |
|
|
619 | (1) |
|
|
620 | (1) |
|
|
621 | (10) |
|
|
623 | (2) |
|
|
625 | (1) |
|
Subscribing to a Notification |
|
|
626 | (2) |
|
|
628 | (1) |
|
|
629 | (2) |
|
|
631 | (4) |
|
|
632 | (1) |
|
|
633 | (2) |
|
|
635 | (1) |
|
|
636 | (6) |
|
|
639 | (1) |
|
|
640 | (2) |
|
|
642 | (5) |
|
Registration and Notification |
|
|
643 | (1) |
|
|
644 | (1) |
|
Key-Value Observing Example |
|
|
645 | (2) |
|
|
647 | (2) |
|
|
649 | (4) |
|
|
653 | (20) |
|
Principles of Cocoa Memory Management |
|
|
653 | (1) |
|
Rules of Cocoa Memory Management |
|
|
654 | (1) |
|
What ARC Is and What It Does |
|
|
655 | (1) |
|
How Cocoa Objects Manage Memory |
|
|
656 | (1) |
|
|
657 | (2) |
|
Memory Management of Instance Properties |
|
|
659 | (1) |
|
Retain Cycles and Weak References |
|
|
660 | (2) |
|
Unusual Memory Management Situations |
|
|
662 | (4) |
|
|
663 | (1) |
|
|
664 | (1) |
|
|
665 | (1) |
|
|
666 | (1) |
|
Memory Management of CFTypeRefs |
|
|
666 | (2) |
|
Property Memory Management Policies |
|
|
668 | (3) |
|
Debugging Memory Management Mistakes |
|
|
671 | (2) |
|
14 Communication Between Objects |
|
|
673 | (28) |
|
Visibility Through an Instance Property |
|
|
673 | (1) |
|
Visibility by Instantiation |
|
|
674 | (2) |
|
|
676 | (3) |
|
Visibility by Relationship |
|
|
677 | (1) |
|
|
677 | (2) |
|
Notifications and Key-Value Observing |
|
|
679 | (1) |
|
|
680 | (7) |
|
Alternative Architectures |
|
|
687 | (3) |
|
|
687 | (1) |
|
|
687 | (1) |
|
|
688 | (1) |
|
Protocols and Reactive Programming |
|
|
689 | (1) |
|
|
690 | (11) |
|
Result Builders and Modifiers |
|
|
691 | (1) |
|
|
692 | (2) |
|
|
694 | (1) |
|
|
694 | (2) |
|
|
696 | (1) |
|
|
697 | (4) |
Appendix. C, Objective-C, and Swift |
|
701 | (38) |
Index |
|
739 | |