About the Author |
|
xxvii | |
About the Technical Reviewer |
|
xxix | |
Acknowledgments |
|
xxxi | |
Introduction |
|
xxxiii | |
|
Chapter 1 Swift Programming |
|
|
1 | (26) |
|
1-1 Getting Started with Swift |
|
|
2 | (1) |
|
|
2 | (1) |
|
|
2 | (1) |
|
|
3 | (1) |
|
|
3 | (1) |
|
|
3 | (1) |
|
|
3 | (1) |
|
1-3 Working with Playgrounds |
|
|
4 | (1) |
|
|
4 | (1) |
|
|
4 | (1) |
|
|
4 | (1) |
|
|
5 | (1) |
|
1-4 Designing User Interface Elements in a Storyboard |
|
|
6 | (1) |
|
|
6 | (1) |
|
|
6 | (1) |
|
|
6 | (1) |
|
|
7 | (1) |
|
|
8 | (1) |
|
|
8 | (1) |
|
|
8 | (1) |
|
|
8 | (1) |
|
|
9 | (1) |
|
1-6 Formatting Numbers as Strings |
|
|
10 | (1) |
|
|
10 | (1) |
|
|
10 | (1) |
|
|
10 | (1) |
|
|
10 | (1) |
|
1-7 Getting the Length of a Swift String |
|
|
11 | (1) |
|
|
11 | (1) |
|
|
11 | (1) |
|
|
11 | (1) |
|
|
11 | (1) |
|
1-8 Manipulating Swift Strings |
|
|
12 | (1) |
|
|
12 | (1) |
|
|
12 | (1) |
|
|
12 | (1) |
|
|
13 | (1) |
|
1-9 Manipulating Strings with Native Swift Methods |
|
|
14 | (1) |
|
|
14 | (1) |
|
|
14 | (1) |
|
|
14 | (1) |
|
|
15 | (1) |
|
1-10 Storing Strings on the iOS File System |
|
|
16 | (1) |
|
|
16 | (1) |
|
|
16 | (1) |
|
|
17 | (1) |
|
|
17 | (2) |
|
1-11 Reading a Text File into a String |
|
|
19 | (1) |
|
|
19 | (1) |
|
|
19 | (1) |
|
|
19 | (1) |
|
|
20 | (1) |
|
1-12 Reading and Writing Text Files in Cocoa |
|
|
21 | (1) |
|
|
21 | (1) |
|
|
21 | (1) |
|
|
21 | (1) |
|
|
22 | (1) |
|
1-13 Dealing with Numbers |
|
|
23 | (1) |
|
|
23 | (1) |
|
|
23 | (1) |
|
|
24 | (1) |
|
|
24 | (1) |
|
|
24 | (1) |
|
|
24 | (1) |
|
|
24 | (1) |
|
|
24 | (1) |
|
|
25 | (2) |
|
|
27 | (24) |
|
|
28 | (1) |
|
|
28 | (1) |
|
|
28 | (1) |
|
|
28 | (1) |
|
|
29 | (1) |
|
|
29 | (1) |
|
|
29 | (1) |
|
|
29 | (1) |
|
|
29 | (1) |
|
|
30 | (1) |
|
2-3 Adding Class Properties |
|
|
30 | (1) |
|
|
30 | (1) |
|
|
30 | (1) |
|
|
30 | (1) |
|
|
31 | (1) |
|
2-4 Initializing Class Properties |
|
|
32 | (1) |
|
|
32 | (1) |
|
|
32 | (1) |
|
|
32 | (1) |
|
|
33 | (1) |
|
|
34 | (1) |
|
|
34 | (1) |
|
|
34 | (1) |
|
|
34 | (1) |
|
|
35 | (1) |
|
2-6 Inheriting from Classes |
|
|
36 | (1) |
|
|
36 | (1) |
|
|
36 | (1) |
|
|
36 | (2) |
|
|
38 | (1) |
|
2-7 Implementing Protocols |
|
|
39 | (1) |
|
|
39 | (1) |
|
|
39 | (1) |
|
|
39 | (1) |
|
|
40 | (1) |
|
2-8 Setting Property Observers |
|
|
41 | (1) |
|
|
41 | (1) |
|
|
41 | (1) |
|
|
41 | (1) |
|
|
42 | (1) |
|
2-9 Defining Enumerations |
|
|
43 | (1) |
|
|
43 | (1) |
|
|
43 | (1) |
|
|
43 | (3) |
|
|
46 | (1) |
|
|
47 | (1) |
|
|
47 | (1) |
|
|
47 | (1) |
|
|
47 | (1) |
|
|
48 | (1) |
|
|
49 | (1) |
|
|
49 | (1) |
|
|
49 | (1) |
|
|
49 | (1) |
|
|
50 | (1) |
|
|
51 | (28) |
|
|
52 | (1) |
|
|
52 | (1) |
|
|
52 | (1) |
|
|
52 | (1) |
|
|
53 | (1) |
|
3-2 Counting the Number of Items in an Array |
|
|
53 | (1) |
|
|
53 | (1) |
|
|
53 | (1) |
|
|
53 | (1) |
|
|
54 | (1) |
|
3-3 Managing Items in an Array |
|
|
54 | (1) |
|
|
54 | (1) |
|
|
54 | (1) |
|
|
54 | (1) |
|
|
55 | (1) |
|
3-4 Searching for Items in an Array |
|
|
55 | (1) |
|
|
55 | (1) |
|
|
56 | (1) |
|
|
56 | (1) |
|
|
57 | (1) |
|
|
58 | (1) |
|
|
58 | (1) |
|
|
58 | (1) |
|
|
58 | (1) |
|
|
59 | (1) |
|
3-6 Replacing a Range of Values in an Array |
|
|
60 | (1) |
|
|
60 | (1) |
|
|
60 | (1) |
|
|
60 | (1) |
|
|
60 | (1) |
|
3-7 Iterating Over an Array |
|
|
61 | (1) |
|
|
61 | (1) |
|
|
61 | (1) |
|
|
61 | (1) |
|
|
62 | (1) |
|
3-8 Saving an Array to the File System |
|
|
62 | (1) |
|
|
62 | (1) |
|
|
62 | (1) |
|
|
62 | (1) |
|
|
63 | (1) |
|
3-9 Populating an Array with the Contents of a plist File |
|
|
64 | (1) |
|
|
64 | (1) |
|
|
64 | (1) |
|
|
64 | (1) |
|
|
65 | (1) |
|
|
66 | (1) |
|
|
66 | (1) |
|
|
66 | (1) |
|
|
66 | (1) |
|
|
67 | (1) |
|
3-11 Creating a Dictionary |
|
|
68 | (1) |
|
|
68 | (1) |
|
|
68 | (1) |
|
|
68 | (1) |
|
|
68 | (1) |
|
3-12 Managing Items in a Dictionary |
|
|
69 | (1) |
|
|
69 | (1) |
|
|
69 | (1) |
|
|
69 | (1) |
|
|
70 | (1) |
|
3-13 Implementing the Hashable Protocol |
|
|
70 | (1) |
|
|
70 | (1) |
|
|
70 | (1) |
|
|
70 | (1) |
|
|
71 | (1) |
|
3-14 Iterating Through Items in a Dictionary |
|
|
72 | (1) |
|
|
72 | (1) |
|
|
72 | (1) |
|
|
72 | (1) |
|
|
73 | (1) |
|
3-15 Saving a Dictionary to the File System |
|
|
74 | (1) |
|
|
74 | (1) |
|
|
74 | (1) |
|
|
74 | (1) |
|
|
75 | (1) |
|
3-16 Populating a Dictionary with the Contents of a Property List File |
|
|
76 | (1) |
|
|
76 | (1) |
|
|
76 | (1) |
|
|
76 | (1) |
|
|
77 | (2) |
|
Chapter 4 Advanced Swift Programming |
|
|
79 | (28) |
|
|
79 | (1) |
|
|
80 | (1) |
|
|
80 | (1) |
|
|
80 | (1) |
|
|
80 | (1) |
|
4-2 Writing Trailing Closures |
|
|
81 | (1) |
|
|
81 | (1) |
|
|
81 | (1) |
|
|
81 | (1) |
|
|
82 | (1) |
|
4-3 Overloading the Equality Operator |
|
|
82 | (1) |
|
|
82 | (1) |
|
|
82 | (1) |
|
|
83 | (1) |
|
|
83 | (1) |
|
4-4 Checking for Reference Equality |
|
|
84 | (1) |
|
|
84 | (1) |
|
|
84 | (1) |
|
|
84 | (1) |
|
|
84 | (1) |
|
4-5 Implementing Generic Functions |
|
|
85 | (1) |
|
|
85 | (1) |
|
|
85 | (1) |
|
|
86 | (1) |
|
|
86 | (1) |
|
4-6 Implementing Generic Classes |
|
|
87 | (1) |
|
|
87 | (1) |
|
|
87 | (1) |
|
|
87 | (1) |
|
|
88 | (1) |
|
4-7 Working with Local Dates and Times |
|
|
89 | (1) |
|
|
89 | (1) |
|
|
89 | (1) |
|
|
89 | (1) |
|
|
90 | (2) |
|
4-8 Creating a Unit Test Project |
|
|
92 | (1) |
|
|
92 | (1) |
|
|
92 | (1) |
|
|
92 | (1) |
|
|
92 | (2) |
|
|
94 | (1) |
|
|
94 | (1) |
|
|
94 | (1) |
|
|
94 | (2) |
|
|
96 | (2) |
|
4-10 Performance Testing with XCTest |
|
|
98 | (1) |
|
|
98 | (1) |
|
|
98 | (1) |
|
|
98 | (1) |
|
|
98 | (1) |
|
4-11 Creating Mock Objects for Testing |
|
|
99 | (1) |
|
|
100 | (1) |
|
|
100 | (1) |
|
|
100 | (1) |
|
|
100 | (2) |
|
4-12 Testing Asynchronous Code |
|
|
102 | (1) |
|
|
102 | (1) |
|
|
102 | (1) |
|
|
103 | (1) |
|
|
104 | (3) |
|
Chapter 5 iOS Applications |
|
|
107 | (36) |
|
5-1 Creating a New iOS Application |
|
|
107 | (1) |
|
|
107 | (1) |
|
|
107 | (1) |
|
|
108 | (1) |
|
5-2 Adding a UILabel to a View |
|
|
109 | (1) |
|
|
109 | (1) |
|
|
109 | (1) |
|
|
109 | (1) |
|
|
110 | (1) |
|
5-3 Adding a UIButton to a View |
|
|
111 | (1) |
|
|
111 | (1) |
|
|
111 | (1) |
|
|
111 | (2) |
|
|
113 | (1) |
|
5-4 Adding a UITextField to a View |
|
|
114 | (1) |
|
|
114 | (1) |
|
|
114 | (1) |
|
|
114 | (1) |
|
|
115 | (1) |
|
5-5 Positioning UIViews in Auto Layout Using NSConstraints |
|
|
116 | (1) |
|
|
116 | (1) |
|
|
116 | (1) |
|
|
117 | (2) |
|
|
119 | (2) |
|
5-6 Repositioning a View to Accommodate the Keyboard |
|
|
121 | (1) |
|
|
121 | (1) |
|
|
121 | (1) |
|
|
121 | (4) |
|
|
125 | (2) |
|
5-7 Displaying an Alert with UIAlertController |
|
|
127 | (1) |
|
|
127 | (1) |
|
|
127 | (1) |
|
|
127 | (2) |
|
|
129 | (1) |
|
5-8 Using UIAlertController to Collect User Input |
|
|
130 | (1) |
|
|
130 | (1) |
|
|
130 | (1) |
|
|
130 | (2) |
|
|
132 | (1) |
|
5-9 Creating a UITableView |
|
|
133 | (1) |
|
|
133 | (1) |
|
|
133 | (1) |
|
|
133 | (3) |
|
|
136 | (2) |
|
5-10 Swiping to Delete an Item from a UITableView |
|
|
138 | (1) |
|
|
138 | (1) |
|
|
138 | (1) |
|
|
139 | (1) |
|
|
140 | (3) |
|
Chapter 6 OS X Applications |
|
|
143 | (36) |
|
6-1 Creating an OS X Application |
|
|
144 | (1) |
|
|
144 | (1) |
|
|
144 | (1) |
|
|
144 | (1) |
|
|
145 | (1) |
|
6-2 Adding a View to a Window |
|
|
146 | (1) |
|
|
146 | (1) |
|
|
146 | (1) |
|
|
146 | (1) |
|
|
147 | (1) |
|
6-3 Adding a Menu and Menu Items |
|
|
148 | (1) |
|
|
148 | (1) |
|
|
148 | (1) |
|
|
148 | (2) |
|
|
150 | (1) |
|
6-4 Adding a Button to a Window |
|
|
151 | (1) |
|
|
151 | (1) |
|
|
151 | (1) |
|
|
152 | (1) |
|
|
153 | (1) |
|
|
154 | (1) |
|
|
154 | (1) |
|
|
154 | (1) |
|
|
154 | (1) |
|
|
155 | (1) |
|
6-6 Displaying an Image in a Window |
|
|
156 | (1) |
|
|
156 | (1) |
|
|
156 | (1) |
|
|
156 | (2) |
|
|
158 | (1) |
|
6-7 Adjusting Contents When a Window Is Resized |
|
|
158 | (1) |
|
|
158 | (1) |
|
|
158 | (1) |
|
|
158 | (3) |
|
|
161 | (1) |
|
6-8 Implementing an NSTableView |
|
|
162 | (1) |
|
|
162 | (1) |
|
|
162 | (1) |
|
|
163 | (5) |
|
|
168 | (2) |
|
6-9 Sorting an NSTableView |
|
|
170 | (1) |
|
|
170 | (1) |
|
|
170 | (1) |
|
|
170 | (4) |
|
|
174 | (2) |
|
6-10 Handling the Selection of an NSTableView Row |
|
|
176 | (1) |
|
|
176 | (1) |
|
|
176 | (1) |
|
|
176 | (1) |
|
|
177 | (2) |
|
Chapter 7 Files and Directories |
|
|
179 | (20) |
|
7-1 Locating Specialized Directories |
|
|
180 | (1) |
|
|
180 | (1) |
|
|
180 | (1) |
|
|
180 | (2) |
|
|
182 | (1) |
|
7-2 Checking for the Existence of a File or Directory |
|
|
182 | (1) |
|
|
182 | (1) |
|
|
182 | (1) |
|
|
182 | (1) |
|
|
183 | (1) |
|
|
184 | (1) |
|
|
184 | (1) |
|
|
184 | (1) |
|
|
185 | (1) |
|
|
185 | (1) |
|
|
186 | (1) |
|
|
186 | (1) |
|
|
186 | (1) |
|
|
187 | (1) |
|
|
187 | (1) |
|
7-5 Deleting Files and Directories |
|
|
188 | (1) |
|
|
188 | (1) |
|
|
188 | (1) |
|
|
188 | (1) |
|
|
189 | (2) |
|
7-6 Getting a List of Files from a Path |
|
|
191 | (1) |
|
|
191 | (1) |
|
|
191 | (1) |
|
|
191 | (1) |
|
|
192 | (1) |
|
7-7 Archiving Objects to Files |
|
|
193 | (1) |
|
|
193 | (1) |
|
|
193 | (1) |
|
|
193 | (1) |
|
|
194 | (1) |
|
7-8 Archiving Custom Classes to Files |
|
|
195 | (1) |
|
|
195 | (1) |
|
|
195 | (1) |
|
|
195 | (1) |
|
|
196 | (3) |
|
|
199 | (26) |
|
8-1 Threading with NSThread |
|
|
199 | (1) |
|
|
199 | (1) |
|
|
199 | (1) |
|
|
200 | (1) |
|
|
201 | (1) |
|
8-2 Synchronizing Threads |
|
|
202 | (1) |
|
|
202 | (1) |
|
|
202 | (1) |
|
|
203 | (1) |
|
|
203 | (1) |
|
8-3 Using Grand Central Dispatch for Threading |
|
|
204 | (1) |
|
|
204 | (1) |
|
|
204 | (1) |
|
|
205 | (1) |
|
|
206 | (1) |
|
8-4 Using NSOperations and NSOperationsQueue |
|
|
207 | (1) |
|
|
207 | (1) |
|
|
207 | (1) |
|
|
207 | (2) |
|
|
209 | (1) |
|
8-5 Completing Tasks in the Background in iOS |
|
|
210 | (1) |
|
|
210 | (1) |
|
|
210 | (1) |
|
|
210 | (1) |
|
|
211 | (1) |
|
8-6 Downloading Content in the Background |
|
|
212 | (1) |
|
|
212 | (1) |
|
|
212 | (1) |
|
|
212 | (4) |
|
|
216 | (2) |
|
8-7 Creating Long-Running Background Tasks |
|
|
218 | (1) |
|
|
218 | (1) |
|
|
218 | (1) |
|
|
218 | (5) |
|
|
223 | (2) |
|
|
225 | (26) |
|
|
225 | (1) |
|
|
225 | (1) |
|
|
225 | (1) |
|
|
226 | (1) |
|
|
227 | (4) |
|
|
231 | (1) |
|
|
231 | (1) |
|
|
231 | (1) |
|
|
231 | (3) |
|
|
234 | (1) |
|
|
235 | (1) |
|
|
235 | (1) |
|
|
235 | (1) |
|
|
235 | (1) |
|
|
236 | (1) |
|
9-4 Checking for Network Connectivity |
|
|
237 | (1) |
|
|
237 | (1) |
|
|
237 | (1) |
|
|
237 | (1) |
|
|
238 | (2) |
|
|
240 | (1) |
|
|
240 | (1) |
|
|
240 | (1) |
|
|
240 | (2) |
|
|
242 | (2) |
|
9-6 Posting Data to a REST API |
|
|
244 | (1) |
|
|
244 | (1) |
|
|
244 | (1) |
|
|
244 | (2) |
|
|
246 | (5) |
|
|
251 | (26) |
|
10-1 Creating a Data Model |
|
|
252 | (1) |
|
|
252 | (1) |
|
|
252 | (1) |
|
|
252 | (2) |
|
10-2 Creating Model Classes |
|
|
254 | (1) |
|
|
254 | (1) |
|
|
254 | (1) |
|
|
254 | (2) |
|
|
256 | (1) |
|
10-3 Creating a Data Store |
|
|
257 | (1) |
|
|
257 | (1) |
|
|
257 | (1) |
|
|
257 | (3) |
|
|
260 | (2) |
|
10-4 Creating a Managed Object Context |
|
|
262 | (1) |
|
|
262 | (1) |
|
|
262 | (1) |
|
|
262 | (1) |
|
|
263 | (1) |
|
|
264 | (1) |
|
|
264 | (1) |
|
|
264 | (1) |
|
|
264 | (1) |
|
|
265 | (1) |
|
10-6 Creating an NSFetchRequest |
|
|
266 | (1) |
|
|
266 | (1) |
|
|
266 | (1) |
|
|
266 | (1) |
|
|
267 | (1) |
|
10-7 Populating a UITableView with a Fetched Results Controller |
|
|
268 | (1) |
|
|
268 | (1) |
|
|
268 | (1) |
|
|
268 | (3) |
|
|
271 | (2) |
|
|
273 | (1) |
|
|
273 | (1) |
|
|
273 | (1) |
|
|
273 | (1) |
|
|
274 | (1) |
|
10-9 Searching for Entities |
|
|
275 | (1) |
|
|
275 | (1) |
|
|
275 | (1) |
|
|
275 | (1) |
|
|
275 | (2) |
|
Chapter 11 Advanced iOS 8 Features |
|
|
277 | (26) |
|
11-1 Creating a Today Extension |
|
|
277 | (1) |
|
|
277 | (1) |
|
|
277 | (1) |
|
|
277 | (4) |
|
|
281 | (2) |
|
11-2 Creating a Custom Keyboard Extension |
|
|
283 | (1) |
|
|
283 | (1) |
|
|
283 | (1) |
|
|
283 | (3) |
|
|
286 | (1) |
|
11-3 Creating a Sharing Extension |
|
|
287 | (1) |
|
|
287 | (1) |
|
|
287 | (1) |
|
|
287 | (5) |
|
|
292 | (2) |
|
11-4 Creating an Action Extension |
|
|
294 | (1) |
|
|
294 | (1) |
|
|
294 | (1) |
|
|
294 | (3) |
|
|
297 | (2) |
|
11-5 Creating a WatchKit Application |
|
|
299 | (1) |
|
|
299 | (1) |
|
|
299 | (1) |
|
|
299 | (2) |
|
|
301 | (2) |
Index |
|
303 | |