-
Notifications
You must be signed in to change notification settings - Fork 1
/
1day_session1.html
562 lines (481 loc) · 17.6 KB
/
1day_session1.html
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>KW iOS Training: Session 1</title>
<meta name="description" content="KW iOS Training: Session 1">
<meta name="author" content="Christina Moulton">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="css/reveal.min.css">
<link rel="stylesheet" href="css/theme/sky_lowercase_title.css" id="theme">
<!-- For syntax highlighting -->
<!--<link rel="stylesheet" href="lib/css/zenburn.css">-->
<!-- If the query includes 'print-pdf', use the PDF print sheet -->
<script>
document.write( '<link rel="stylesheet" href="css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<h1>Beginning Professional iPhone App Development</h1>
<p>Christina Moulton, <a href="http://teakmobile.com">Teak Mobile Inc.</a></p>
<p><a href="http://twitter.com/ChristinaMltn">@ChristinaMltn</a>, <a href="mailto:christina@teakmobile.com">christina@teakmobile.com</a></p>
<p><a href="kwiostraining.eventbrite.ca">KW iOS Training</a></p>
</section>
<section>
<h2>About Me</h2>
<p>Christina Moulton</p>
<p>Freelance iOS dev</p>
<p>Suffered through crappy syntax you won't need to bother with</p>
</section>
<section>
<h2>What will I learn?</h2>
<p>How to create basic native iOS apps from scratch without wasting a ton of time trying to work against the tools and the language.</p>
<p>Issues that stop people from learning iOS development on their own</p>
<!--<ul>
<li>Objective-C oddities</li>
<li>How to use Xcode, including hooking up views to code</li>
<li>What does the SDK make easy and what can’t be done</li>
<li>Key resources: tutorials, documentation, and third party libraries</li>
</ul>-->
</section>
<section>
<h2>What will I NOT learn?</h2>
<p>Game programming</p>
<p>Everything</p>
</section>
<section>
<h2>Why iOS?</h2>
<p>App Store revenues: $5B im 2012</p>
<p>Employment & contract opportunities</p>
<p>Something different</p>
<p>Getting to know you: Why? What's your background?</p>
</section>
<section>
<h2>Why native apps?</h2>
<p>Speed</p>
<p>Ease of UI development & hardware integration</p>
<p>Richer UX</p>
<p>Earlier access to all device features</p>
<p>Easier persistence and offline operation</p>
<p><em>More later (time permitting)</em></p>
</section>
<section>
<h2>What stops devs from getting in to iOS?</h2>
<p>Syntax</p>
<p>Design patterns</p>
<p>Interface Builder</p>
<p>Apple's web-based tools</p>
</section>
<section>
<h2>Schedule</h2>
<p><b>Session 1: Design Patterns & Obj-C Features, Apple's Tools, SDK & Core Classes</b></p>
<p>Exercise 1: Interface Builder, IBOutlets & IBActions</p>
<p>Exercise 2: Tableviews, datasources & delegates</p>
<p><em>Lunch</em></p>
<p>Session 2: iOS App Ecosystem, 3rd Party Tools & Testing, Key Resources</p>
<p>(Storyboards & UI Components)</p>
<p>Exercise 3: JSON REST APIs & Storyboards</p>
<p>Session 3: Code Signing, App Store Submission, What Should Be a Native App vs. Web App</p>
<p>Time permitting: In App Purchase, Autolayout</p>
</section>
<section>
<h2>What You'll Need</h2>
<ul>
<li>Mac running OS X</li>
<li>Xcode 5 (4 is ok)</li>
<li>Wifi</li>
<li>(Optional: iOS Device running at least iOS 6)</li>
</ul>
</section>
<section>
<h2>Session 1:</h2>
<h3>Design patterns & language features:</h3>
<ul>
<li>Delegate Pattern</li>
<li>Blocks (Closures)</li>
<li>Categories</li>
<li>Objective-C Memory Management</li>
<li>Message Sending Model</li>
<br />
</ul>
<h3>Apple’s Tools: Xcode, Interface Builder</h3>
<h3>iOS SDK Frameworks & Core Classes</h3>
</section>
<section>
<h2>iOS Background</h2>
<p>Objective-C + SDK</p>
<p>UI: Direct Manipulation & Multi-Touch</p>
<p>Just released iOS 7</p>
<img src="img/ios7uptake.png" />
</section>
<section>
<h2>Objective-C: Syntax</h2>
<p>Class Header (.h)</p>
<pre><code data-trim>#import "AnyOtherHeaderFile.h"
@interface MyClass : SuperClass {
// declare instance variables
// (optional)
NSInteger _myInteger;
}
// define properties
@property (nonatomic, strong) NSString *myString;
// define methods
- (anytype)doIt;
- (anytype)doItWithA:(anytype)a;
- (anytype)doItWithA:(anytype)a andB:(anytype)b;
+ (anytype)classDoIt;
@end</code></pre>
<p><a href="http://cdn5.raywenderlich.com/downloads/RW-Objective-C-Cheatsheet-v1_2.pdf">Cheatsheet from RayWenderlich.com</a></p>
</section>
<section>
<h2>Objective-C: Syntax</h2>
<p>Class Implementation (.m)</p>
<pre><code data-trim>#import "MyClass.h"
@implementation MyClass
// implement methods (including custom inits)
- (id)init
{
self = [super init];
if (self) { // initialize ivars
}
return self;
}
- (anytype)doItWithA:(anytype)a andB:(anytype)b;
{
NSLog(@"Doing it with %@ and %@", a, b);
return a;
}
@end</code></pre>
</section>
<section>
<h2>Objective-C: Classes</h2>
<p>Messaging:</p>
<pre><code data-trim>[receiver message];</code></pre>
<pre><code data-trim>[receiver messageWithParameter:aParameter];</code></pre>
<p>Create an Instance of a Class & Call Methods</p>
<pre><code data-trim>MyClass *myObject = [[MyClass alloc] init];
[myObject doIt];
id returnValue = [myObject doItWithA:anA andB:aB];
[MyClass classDoIt];</code></pre>
</section>
<section>
<h2>Objective-C: Variables</h2>
<pre><code data-trim>anyType myVariable;</code></pre>
<pre><code data-trim>NSInteger anInteger;
NSObject *anObject;
id anotherObject;</code></pre>
<p>Common Types</p>
<p>int (NSInteger), float, double</p>
<p>BOOL: YES, NO, TRUE, FALSE</p>
<p>ClassName *: e.g., NSString *, NSArray *</p>
<p>id: Ref to any object (NSObject * or subclass)</p>
</section>
<section>
<h2>Objective-C: Properties</h2>
<pre>myObject.myString = @"a String";
[myObject setMyString:@"a String"];
aString = myObject.myString;
aString = [myObject myString];</code></pre>
<p>Compile-time autosynthesis since Xcode 4.4</p>
</section>
<section>
<h2>Objective-C: Properties</h2>
<p>Qualifiers in declaration</p>
<pre><code data-trim>@property (nonatomic, strong) aType aProperty;</code></pre>
<p>ARC: strong, weak</p>
<p>Primitives: assign, copy</p>
<p>Threading: nonatomic, atomic</p>
<p>Accessors: readwrite, readonly</p>
</section>
<section>
<h2>Objective-C: NSString</h2>
<pre><code data-trim>NSString *catOne = @"Mittens";
NSString *catTwo = @"Mr. Bigglesworth";
NSString *statement = [NSString stringWithFormat:
@"The cats to be worshipped are %@ and %@",
catOne, catTwo];
NSLog(@"%@", statement);</code></pre>
<pre><code data-trim>NSString *tipString = @"24.99";
float tipFloat = [tipString floatValue];</code></pre>
<p>Also NSMutableString</p>
</section>
<section>
<h2>Objective-C: NSArray</h2>
<pre><code data-trim style="font-size: 20pt;">NSMutableArray *array = [NSMutableArray arrayWithObjects:
catOne, catTwo, nil];
[array addObject:@"Sylvester"];
NSString *sylvester = [array objectAtIndex:2];
NSLog(@"That cat's name is: %@", sylvester);
NSLog(@"%d cats!", array.count);
for (NSString *cat in array) {
NSLog(@"Cat: %@", cat);
}</code></pre>
<pre><code data-trim style="font-size: 20pt;">// Xcode 4.4+ alt: array[2]
NSArray *anArray = @[@"John", @"Jane", "Waldo"];
NSString *waldo = anArray[2];</code></pre>
<p>Also NSMutableArray, NSSet, NSDictionary</p>
</section>
<section>
<h2>Objective-C: Blocks (Closures)</h2>
<p>Encapsulated chunks of code</p>
<pre><code data-trim>int multiplier = 7;
int (^myBlock)(int) = ^(int num) {
return num * multiplier;
};
NSLog(@"%d", myBlock(3)); // prints 21
multiplier = 8;
NSLog(@"%d", myBlock(3)); // still prints 21</code></pre>
<pre><code data-trim>[UIView animateWithDuration:2.0
animations:^ {
self.view.alpha = 1.0;
self.view.frame = CGRectMake(0, 0, 72, 96);
}
];</code></pre>
</section>
<section>
<h2>iOS Design Patterns</h2>
<p>MVC</p>
<p>Singleton</p>
<p>Protocol & Delegate</p>
<p>Decorator: Category</p>
<p>Observer</p>
</section>
<section>
<h2>MVC</h2>
<p>Model: Data Model Objects</p>
<p>View: UIView & subclasses</p>
<p>Controller: UIViewController & subclasses</p>
<p>Model <-> Controller <-> View</p>
<p>Seldom code views</p>
<p>(E.g., UITableView)</p>
</section>
<section>
<h2>Singleton</h2>
<p>AppDelegate, NSUserDefaults, NSFileManager</p>
<p>Common for resources: Reachability, Location Services, Logging, ...</p>
<p>Thread-safe access</p>
<pre><code data-trim>+ (MySingleton *)sharedInstance
{
static dispatch_once_t once;
static MySingleton * sharedInstance;
dispatch_once(&once, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}</code></pre>
</section>
<section>
<h2>Protocol / Delegate</h2>
<p>Common in UIKit classes, e.g., UITableView Datasource & Delegate</p>
<p>Datasource is a specific type of delegate</p>
<p>Configuration & composition over inheritance</p>
<pre><code data-trim style="font-size:20pt;">@protocol InfoDelegate
- (void)showAppShareView;
- (void)restartTour;
@optional
- (void)optionalMethod;
@end
@interface InfoViewController: UIViewController
@property (nonatomic, strong) id<InfoDelegate> delegate;
@end</code></pre>
</section>
<section>
<h2>Category (Decorator)</h2>
<p>Extend a class with additional methods</p>
<p>Included at compile time</p>
<pre><code data-trim>@interface ClassToAddMethodsTo (category)
// ...methods go here
@end</code></pre>
<pre><code data-trim>@interface NSString (MD5)
- (NSString *)MD5Hash;
@end</code></pre>
<p>No new ivars</p>
</section>
<section>
<h2>Observer</h2>
<p>KVO: Key-Value Observing</p>
<p>Controller can observe Model for changes</p>
<p>Register for notifications</p>
<pre><code data-trim style="font-size:26px;">[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidShow:)
name:UIKeyboardDidShowNotification
object:nil];</code></pre>
<pre><code data-trim style="font-size:26px;">- (void)keyboardDidShow:(NSNotification *)aNotification
{
// ...
}</code></pre>
</section>
<section>
<h2>Memory Management</h2>
<p>The old way: Reference Counting</p>
<p>Need it?</p>
<pre><code data-trim>[anObject retain];</code></pre>
<p>Done with it?</p>
<pre><code data-trim>[anObject release];</code></pre>
<p>Dealloc'd when release count reaches 0</p>
</section>
<section>
<h2>Autorelease</h2>
<p>Return it without retaining it, but don't dealloc until caller is done with it</p>
<pre><code data-trim>- (id)myMethod {
return [[[MyObject alloc] init] autorelease];
}
- (void)someOtherMethod {
id instance = [obj myMethod];
// not dealloc'd until after this method returns
}</code></pre>
</section>
<section>
<h2>Automatic Reference Counting (ARC)</h2>
<p>Retain/release calls inserted by compiler</p>
<p>No reason not to use (iOS 5.0+)</p>
<p>Qualifiers:</p>
<p>Strong: Owns it</p>
<p>Weak: Non-owning reference (e.g., to parent). Set to nil when no strong references to object exist</p>
<p>Unsafe unretained: Non-owning reference. Not set to nil (dangling pointers)</p>
<p>Autoreleasing: Passed by reference and autoreleased on return</p>
</section>
<section>
<h2>Automatic Reference Counting (ARC)</h2>
<p>Consider object graph: Leaks if retain cycles</p>
<pre><code data-trim>@interface ClassA
@property (nonatomic, strong) ClassB *objectB;
@end
@interface ClassB
@property (nonatomic, strong) ClassA *objectA;
@end</code></pre>
<pre><code data-trim>@interface ClassA
@property (nonatomic, strong) ClassB *objectB;
@end
@interface ClassB
@property (nonatomic, weak) ClassA *objectA;
@end</code></pre>
</section>
<section>
<h2>Apple's Tools</h2>
<h3>Xcode</h3>
<h3>Interface Builder</h3>
<h3>iOS Simulator</h3>
<h3>Instruments</h3>
</section>
<section>
<h2>iOS Projects: .xcodeproj</h2>
<p>Xcode windows</p>
<img src="img/xcode.png"/>
</section>
<section>
<h2>iOS Projects: Files</h2>
<p>Project settings & .plist</p>
<p>main.m</p>
<p>-Prefix.pch</p>
<p>AppDelegate</p>
<p>.xib</p>
<p>.storyboard</p>
<p>.xcassets</p>
<p>Tests</p>
<p>Live Demo</p>
</section>
<section>
<h2>iOS Projects: Build & Run</h2>
<p>Simulator: Hardware</p>
</section>
<section>
<h2>Connecting UI to Code</h2>
<pre><code data-trim style="font-size: 20pt">@property (nonatomic, weak) IBOutlet UIButton *myButton;
- (IBAction)myAction:(id)sender;</code></pre>
</section>
<section>
<h2>Exercise 1: Tap Counter</h2>
<p>Create a project with a button and a label</p>
<p>Add an integer property or ivar to track counts</p>
<p>Tapping on the button should change the label text (label.text) to display the number of times the button has been pressed</p>
<p>([NSString stringWithFormat:@"Taps: %d", self.tapCount])</p>
<p><em>Challenges:</em></p>
<p><em>Add a clear count button to restart</em></p>
<p><em>Change to a shake or swipe gesture counter</em></p>
</section>
<section>
<h2>Connecting UI to Code</h2>
<pre><code data-trim style="font-size: 18pt">@property (nonatomic, weak) IBOutlet UIButton *counterButton;
@property (nonatomic, weak) IBOutlet UILabel *counterLabel;
@property (nonatomic) NSInteger tapCount;
- (IBAction)incrementAndUpdateCount:(id)sender
{
self.tapCount++;
self.counterLabel.text = [NSString stringWithFormat:@"Taps: %d",
self.tapCount];
}</code></pre>
</section>
<section>
<h2>Key Classes: <a href="https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/Passbook.html#//apple_ref/doc/uid/TP40006556-CH33-SW1">iOS Technologies</a></h2>
<div style="float:left; width: 33%">
<p>Keyboard & input views</p>
<p>Multitasking</p>
<p>Social media & Sharing</p>
<p>In-App purchase</p>
<p>Game center</p>
</div>
<div style="float:left; width: 33%">
<p>Notifications: Push & local</p>
<p>iAd</p>
<p>AirPrint</p>
<p>Location Services</p>
<p>Sound</p>
</div>
<div style="float:left; width: 33%">
<p>Accessibility</p>
<p>Edit menu</p>
<p>Undo: buttons & shaking</p>
<p>iCloud</p>
<p>Passbook</p>
</div>
</section>
<section>
<h2>Resources</h2>
<p><a href="http://www.raywenderlich.com/tutorials">Ray Wenderlich iPhone Tutorials</a></p>
<p><a href-"https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG">Apple Mobile Human Interface Guidelines</a></p>
</section>
<section>
<h1>Questions?</h1>
<p>Christina Moulton, <a href="http://teakmobile.com">Teak Mobile Inc.</a></p>
<p><a href="http://twitter.com/ChristinaMltn">@ChristinaMltn</a>, <a href="mailto:christina@teakmobile.com">christina@teakmobile.com</a></p>
<div style="float:none; width: 100%">
<p><a href="kwiostraining.eventbrite.ca">KW iOS Training</a></p>
</div>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
progress: true,
history: true,
center: true,
controls: false,
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'linear', // default/cube/page/concave/zoom/linear/fade/none
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
/*{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },*/
{ src: 'plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
{ src: 'plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
</body>
</html>