-
Notifications
You must be signed in to change notification settings - Fork 0
/
360iDev.html
580 lines (498 loc) · 21.1 KB
/
360iDev.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
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
<html>
<head>
<title>Case Study: Implementing an Incremental Store</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="http://static.stackmob.com/js/json2-min.js"></script>
<script type="text/javascript" src="http://static.stackmob.com/js/underscore-1.3.3-min.js"></script>
<script type="text/javascript" src="http://static.stackmob.com/js/backbone-0.9.2-min.js"></script>
<script type="text/javascript" src="http://static.stackmob.com/js/stackmob-js-0.2.1-min.js"></script>
<script type="text/javascript" src="http://static.stackmob.com/resources/js/jsonFormatter-0.1.0-min.js"></script>
<script type="text/javascript" src="stackmob-debug.js"></script>
<!-- Include required JS files -->
<script type="text/javascript" src="../syntaxhighlighter/scripts/shCore.js"></script>
<script type="text/javascript" src="../syntaxhighlighter/scripts/shBrushJScript.js"></script>
<script type="text/javascript" src="../syntaxhighlighter/scripts/shBrushXml.js"></script>
<script type="text/javascript" src="../syntaxhighlighter/scripts/shBrushJava.js"></script>
<script type="text/javascript" src="../syntaxhighlighter/scripts/shBrushCpp.js"></script>
<script type="text/javascript" src="../syntaxhighlighter/scripts/shBrushObjC.js"></script>
<script type="text/javascript" src="../syntaxhighlighter/scripts/shBrushPlain.js"></script>
<link href="../syntaxhighlighter/styles/shCoreMidnight.css" rel="stylesheet" type="text/css" />
<link href="../syntaxhighlighter/styles/shThemeMidnight.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.syntaxhighlighter {
margin: 0px !important; padding-top: 15px; padding-bottom: 15px;
border-radius: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px;
}
</style>
<script type="text/javascript">
StackMob.init({
appName: 'javascript',
clientSubdomain: 'stackmob',
apiVersion: 0
});
var Todo = StackMob.Model.extend({
schemaName: 'todo'
});
var Todos = StackMob.Collection.extend({
model: Todo
});
$(document).ready(function() {
SyntaxHighlighter.config.tagName = 'code';
SyntaxHighlighter.config.toolbar = false;
SyntaxHighlighter.all();
Reveal.addEventListener('stampede', function() {
$('#stampede').attr('src', 'http://dl.dropbox.com/u/77348001/stampede.gif');
});
});
</script>
<link rel="stylesheet" href="../reveal.js/css/reset.css">
<link rel="stylesheet" href="../reveal.js/css/main.css">
<style type="text/css" media="screen">
.button, .button a
{
background: #98be47;
background: linear-gradient(top, #a8cf43, #98be47);
background: -moz-linear-gradient(top, #a8cf43, #98be47);
background: -ms-linear-gradient(top, #a8cf43, #98be47);
background: -o-linear-gradient(top, #a8cf43, #98be47);
background: -webkit-linear-gradient(top, #a8cf43, #98be47);
border: 1px solid #8cac42;
border-bottom-color: #7b9b36;
border-radius: 4px;
border-top-color: #94b146;
box-shadow: 0 2px 2px rgba(0, 0, 0, .2), inset 0 1px 0 rgba(255, 255, 255, .5);
color: #fff !important;
cursor: pointer;
font-family: "Helvetica Neue", Arial, sans-serif;
font-size: 26px;
font-weight: bold;
moz-border-radius: 4px;
moz-box-shadow: 0 2px 2px rgba(0, 0, 0, .2), inset 0 1px 0 rgba(255, 255, 255, .5);
ms-border-radius: 4px;
ms-box-shadow: 0 2px 2px rgba(0, 0, 0, .2), inset 0 1px 0 rgba(255, 255, 255, .5);
o-border-radius: 4px;
o-box-shadow: 0 2px 2px rgba(0, 0, 0, .2), inset 0 1px 0 rgba(255, 255, 255, .5);
padding: 6px 14px;
text-decoration: none;
text-shadow: 0 -1px 0 rgba(0, 0, 0, .4);
webkit-border-radius: 4px;
webkit-box-shadow: 0 2px 2px rgba(0, 0, 0, .2), inset 0 1px 0 rgba(255, 255, 255, .5);
}
.button:hover, .button a:hover
{
background: #67a215;
background: linear-gradient(top, #9dbf46, #67a215);
background: -moz-linear-gradient(top, #9dbf46, #67a215);
background: -ms-linear-gradient(top, #9dbf46, #67a215);
background: -o-linear-gradient(top, #9dbf46, #67a215);
background: -webkit-linear-gradient(top, #9dbf46, #67a215);
border: 1px solid #699631;
border-bottom-color: #457119;
border-top-color: #6d9e34;
color: rgba(250, 250, 250, .96);
text-decoration: none;
text-shadow: 0 -1px 0 rgba(0, 0, 0, .8);
}
.button:active, .button a:active
{
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5);
moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5);
ms-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5);
o-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5);
padding: 4px 14px 7px;
webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5);
}
.button.blue, .button.blue a
{
background: #6bbad7;
background: linear-gradient(top, #76cced, #6bbad7);
background: -moz-linear-gradient(top, #76cced, #6bbad7);
background: -ms-linear-gradient(top, #76cced, #6bbad7);
background: -o-linear-gradient(top, #76cced, #6bbad7);
background: -webkit-linear-gradient(top, #76cced, #6bbad7);
border: 1px solid #4ca8ca;
border-bottom-color: #4c9bb9;
border-top-color: #4cb2da;
}
.button.blue:hover, .button.blue a:hover
{
background: #2c9cc6;
background: linear-gradient(top, #3cb7e5, #2c9cc6);
background: -moz-linear-gradient(top, #3cb7e5, #2c9cc6);
background: -ms-linear-gradient(top, #3cb7e5, #2c9cc6);
background: -o-linear-gradient(top, #3cb7e5, #2c9cc6);
background: -webkit-linear-gradient(top, #3cb7e5, #2c9cc6);
border: 1px solid #0083b4;
border-bottom-color: #00709b;
border-top-color: #0092ca;
}
#stackmoblogo {
position: fixed;
top: 20px;
left: 20px;
}
.line { font-size: 50px ! important; }
.logo { width: 400px; }
.pic { height: 300px; }
.big35 { font-size: 35px;}
.big50 { font-size: 50px;}
.big75 { font-size: 75px;}
.big100 { font-size: 100px;}
.top15 { margin-top: 15px; }
.top25 { margin-top: 25px; }
.top35 { margin-top: 35px; }
.top50 { margin-top: 50px; }
.top75 { margin-top: 75px; }
.top100 { margin-top: 100px; }
.lineSpace { line-height: 1.4em }
</style>
</head>
<body>
<!-- <div id="stackmoblogo"><img src="../images/360iDev2.png"></div> -->
<div id="stackmoblogo"><img src="../images/stackmob_small_full_white.png"></div>
<div id="reveal">
<div class="state-background"></div>
<div class="slides">
<section>
<h2>Case Study: Implementing an Incremental Store</h2>
<!-- <h3 class="inverted">StackMob & Objective-C</h3> -->
<!-- <p><span style="font-size: 24px;">(uses Backbone.js)</span></p> -->
<p style="margin-top: 100px;">
<!-- <p><a href="http://www.stackmob.com" target="_blank">stackmob.com</a> | <a href="http://www.twitter.com/stackmob">@stackmob</a> | #stackmob</p> -->
<p class="big50 lineSpace">Matt Vaznaian <br /> matt@stackmob.com <br /> <a href="http://www.twitter.com/mvaznaian" target="_blank">@_mattvaz</a></p>
</p>
</section>
<section>
<h2>Goals for this Presentation</h2>
<section>
<p class="big50 top50 lineSpace">To introduce you to a powerful class that allows Core Data to talk to a remote service.</p>
</section>
<section>
<p class="big50 top50 lineSpace">To walk you through the implementation of an NSIncrementalStore subclass.</p>
</section>
<section>
<p class="big50 lineSpace">To share the implementation challenges and solutions.</p>
<p><img class="pic" src="../images/bill-nye.jpeg"></p>
</section>
</section>
<section>
<p>What is <img class="logo" src="../images/stackmob_fulllogo_white.png" > ?</p>
<br/>
<ul class="lineSpace">
<li>A backend platform for mobile developers.</li>
<li>Drop the SDK into your XCode application and gain access to a customizable backend in the cloud.</li>
<li>Additional Features: Push Notifications, User/Facebook/Twitter Authentication, Custom Server Side Code, API Versioning.</li>
</ul>
</section>
<section>
<h2>What problem were we trying to solve?</h2>
<section>
<p class="big50 top50 lineSpace">Improve the experience of using a mobile development platform.</p>
<p><img src="../images/restfulwebservices.png"></p>
</section>
<section>
<p class="big50 top75 lineSpace">What existing iOS knowledge can we leverage?</p>
</section>
<section>
<p class="big50 top75">Core Data?</p>
</section>
<section>
<p class="top75"><img src="../images/sqlite370_banner.gif"> <img src="../images/stackmob_logo.png"></p>
</section>
<section>
<p class="big75 top75">NSIncrementalStore!</p>
</section>
</section>
<section>
<h2>So, have you used Core Data?</h2>
<img src="../images/CoreDataPic.png">
</section>
<section>
<h2>Core Data Overview</h2>
<section>
<p class="big50 top75 lineSpace">“Core Data is an object graph and persistence framework provided by Apple.”</p>
</section>
<section>
<p class="big50 top50">Data Model → NSManagedObjectModel</p>
<p><img src="../images/core-data-model.png"></p>
</section>
<section>
<p class="big50 top25">NSManagedObjectModel &</p>
<p class="big50 top25">Persistent Store Type</p>
<p class="big50 top25">↓</p>
<p class="big75 top50">NSPersistentStoreCoordinator</p>
</section>
<section>
<p class="top50">hasChanges mergePolicy deleteObject: undo: performBlock:</p>
<p class="top75 big75">NSManagedObjectContext</p>
<p class="top75">insertObject: updatedObjects save: undo: refreshObject:</p>
</section>
<section>
<p class="big50 top50">NSManagedObjectContext</p>
<p class="big50 top25">↑ ↓</p>
<p class="big50 top25">NSPersistentStoreCoordinator</p>
<p class="big50 top25">↑ ↓</p>
<p class="big50 top25">Remote Service</p>
</section>
<section>
<p class="big50 top50">NSPredicate</p>
<p class="big25 top50">Apple's way to create query parameters.</p>
<pre><code class="brush: objc; toolbar: false;">
NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"name = %@", username];
</code></pre>
<p class="top25">( <, >, !=, ==, like, between, etc... )</p>
</section>
</section>
<section>
<h2>NSIncrementalStore</h2>
<section>
<p class="big50 top75 lineSpace">“...an abstract superclass defining the API through which Core Data communicates with a store.”</p>
</section>
<section>
<p class="big50 top50">Incremental Store vs. Atomic Store</p>
<p><img src="../images/boxing-gloves.jpeg"></p>
</section>
<section>
<p><img src="../images/mobile-evolution.gif"></p>
</section>
</section>
<section>
<h2>Methods to Override</h2>
<section class="top50">
<p class="big50"><strong>loadMetadata:</strong></p>
<p class="top25 lineSpace">Provide metadata information about the store.</p>
</section>
<section class="top50">
<p class="big50"><strong>executeRequest:WithContext:error:</strong></p>
<p class="top25 lineSpace">Kicks off the execution process.</p>
</section>
<section class="top50">
<p class="big50"><strong>obtainPermanentIDsForObjects:error:</strong></p>
<p class="top25 lineSpace">Creates IDs for newly inserted objects.</p>
</section>
<section class="top50">
<p class="big50"><strong>newValuesForObjectWithID:withContext:error:</strong></p>
<p class="top25 lineSpace">Fills the fault for an object.</p>
</section>
<section class="top50">
<p class="big50"><strong>newValuesForRelationship:forObjectWithID:<br /> withContext:error:</strong></p>
<p class="top25 lineSpace">Fills a fault for an object's relationship.</p>
</section>
</section>
<section>
<h2>Details of implementation</h2>
<section>
<h3>Adding our Incremental Store to the PSC</h3>
<pre><code class="brush: objc; toolbar: false;">
[NSPersistentStoreCoordinator
registerStoreClass:[SMIncrementalStore class]
forStoreType:SMIncrementalStoreType];
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc]
initWithManagedObjectModel:self.managedObjectModel];
NSError *error;
[_persistentStoreCoordinator
addPersistentStoreWithType:SMIncrementalStoreType
configuration:nil
URL:nil
options:[NSDictionary dictionaryWithObject:self
forKey:SM_DataStoreKey]
error:&error];
</code></pre>
</section>
<section>
<h3>Loading meta data</h3>
<ul>
<li><strong>NSStoreTypeKey</strong> - @"SMIncrementalStore"</li>
<li class="top25"><strong>NSStoreUUIDKey</strong> - [[NSProcessInfo processInfo] globallyUniqueString]</li>
</ul>
</section>
<section>
<h3>Creating a new Managed Object</h3>
<p><img src="../images/dog_entity.png"></p>
</section>
<section>
<h3>Creating a new Managed Object</h3>
<pre><code class="brush: objc; toolbar: false;">
Dog *newDog = [NSEntityDescription
insertNewObjectForEntityForName:@"Dog"
inManagedObjectContext:self.managedObjectContext];
[newDog setValue:@"Bandit" forKey:@"name"];
[newDog setValue:@"Border Collie" forKey:@"type"];
// Assign unique ID for remote service if needed
[newDog setValue:[newDog sm_assignObjectId]
forKey:[newDog sm_primaryKeyField]];
</code></pre>
</section>
<section>
<h3>Managed Object Context After Creation</h3>
<p><img src="../images/ManagedObjectContext.png"></p>
</section>
<section>
<h3>Making A Save Request</h3>
<pre><code class="brush: objc; toolbar: false;">
NSError *error = nil;
BOOL success = [self.managedObjectContext save:&error];
</code></pre>
</section>
<section>
<p class="big50 top25">obtainPermanentIDsForObjects:error:</p>
<ul class="lineSpace">
<li class="top25">NSManagedObjectID ← Reference Object</li>
<li>Reference Object ← valueForKey:@"dog_id"</li>
<br/>
<li>NSManagedObjectID ↔ Database ID</li>
</ul>
</section>
<section>
<p class="big50 top25">executeRequest:WithContext:error:</p>
<ul>
<li class="top25 big50 lineSpace"><strong>NSSaveRequestType</strong> → handleSaveRequest:context:error:</li>
<li class="top25 big50 lineSpace"><strong>NSFetchRequestType</strong> → handleFetchRequest:context:error:</li>
</ul>
</section>
<section>
<p class="big50 top25 lineSpace">"If the save request contains nil values for the inserted/updated/deleted/locked collections, you should treat it as a request to save the store metadata."</p>
</section>
<section>
<p class="big50 top25">handleSaveRequest:context:error:</p>
</br>
<pre><code class="brush: plain; toolbar: false;">
For each bucket (inserted/updated/deleted):
For each item in bucket:
Serialize Core Data object to correct form (NSDictionary);
Persist to Remote Database (StackMob);
Report success or error;
end
end
</code></pre>
</section>
<section>
<p class="big50 top25">handleFetchRequest:context:error:</p>
<pre><code class="brush: plain; toolbar: false;">
Switch ( NSFetchRequestResultType ):
case NSManagedObjectResultType:
Serialize fetchRequest into REST-based query;
Execute query on Database (StackMob);
Deserialize results into instances of NSManagedObjectID;
case NSManagedObjectIDResultType:
Return IDs from results of NSManagedObjectResultType;
case NSDictionaryResultType:
break;
case NSCountResultType:
break;
default:
break;
end
</code></pre>
</section>
<section>
<p class="big50 top25">Serializing Fetch Request</p>
<ul>
<li class="top25">Identify the Entity.</li>
<li class="top25">Compound or Comparison Predicate?</li>
<li class="top25">Convert each predicate type.</li>
<li class="top25">Chain together and set as http request parameters.</li>
<li class="top25">Use fetchOffset and fetchLimit to set query Range.</li>
<li class="top25">Convert any other supported variables.</li>
</ul>
</section>
<section>
<p class="big50 top25">newValuesForObjectWithID:withContext:error:</p>
<ul>
<li class="top25">Called to fill a fault.</li>
<li class="top25">Read from local cache or remote database.</li>
<li class="top25">Return value is instance of NSIncrementalStoreNode, a node representing a single record in a persistent store.</li>
</ul>
</section>
<section>
<p class="big50 top25">newValuesForRelationship:forObjectWithID:<br/>withContext:error:</p>
<ul>
<li class="top25">Called to fill a relationship fault.</li>
<li class="top25">Read from local cache or remote database.</li>
<li class="top25">If To-One, return NSManagedObjectID for related object.</li>
<li class="top25">If To-Many, return NSArray of NSManagedObjectIDs for related objects.</li>
</ul>
</section>
<section>
<p><img src="../images/borat-nsinc.jpeg"></p>
</section>
</section>
<section>
<h2>Hurdles along the way</h2>
<section>
<p class="big50 top50 lineSpace">The serialization process:<br/>Core Data ↔ StackMob.</p>
</section>
<section>
<p class="big50 top50 lineSpace">Autoreleasing errors so they propagate up.</p>
</section>
<section>
<p class="big50 top50 lineSpace">Designing for a great experience.</p>
</section>
</section>
<section>
<h2>What's next?</h2>
<p class="big50 top50">Phase 2: Offline Sync</p>
<p class="top25 big50">... plus more Core Data feature support!
</section>
<section>
<h2>Thank You!</h2>
<p><img src="../images/hercmanpic.png"></p>
</section>
<section>
<h2>Questions? Reach Out!</h2>
<p class="big50 top25">matt@stackmob.com | <a href="http://www.twitter.com/mvaznaian" target="_blank">@_mattvaz</a></p>
<br />
<h2>Try it out!</h2>
<p class="big50">Download the SDK today @ </p>
<p class="big50 top25"><a href="https://www.stackmob.com/platform/start">https://www.stackmob.com/platform/start</a></p>
<p class="big50 top25">Github: <a href="https://github.com/stackmob/stackmob-ios-sdk">/stackmob/stackmob-ios-sdk</a></p>
<br />
<h2>Want the slides?</h2>
<p class="big50 top25"><a href="http://bit.ly/RDv5as">bit.ly/RDv5as</a></p>
</section>
<section>
<h2>Images Sources</h2>
<ul>
<li>restfulwebservices.png - http://www.trachtenberg.com/blog/2006/11/06/rest-vs-httppox-vs-soap/</li>
<li>sqlite370_banner.gif - http://www.sqlite.org/index.html/</li>
<li>core-data-model.png - http://www.cod3r.com/2009/05/working-with-core-data/</li>
<li>boxing-gloves.jpeg - http://waggeneredstrom.com/blog/2012/06/07/cause-marketing-v-corporate-philanthropy/</li>
<li>mobile-evolution.gif - http://www.celtnet.org.uk/mobile-phone/mobile-phone-information.html</li>
<li>borat-nsinc.jpeg - http://memegenerator.net/instance/26303852/</li>
<li>bill-nye.jpeg - http://www.quickmeme.com/meme/3q5lh3/</li>
</ul>
</section>
</div>
<!-- The navigational controls UI -->
<aside class="controls">
<a class="left" href="#">◄</a>
<a class="right" href="#">►</a>
<a class="up" href="#">▲</a>
<a class="down" href="#">▼</a>
</aside>
<!-- Displays presentation progress, max value changes via JS to reflect # of slides -->
<div class="progress"><span></span></div>
</div>
<script type="text/javascript" src="../reveal.js/js/reveal.js"></script>
<script type="text/javascript">
Reveal.initialize({
// Display controls in the bottom right corner
controls: true,
// Display a presentation progress bar
progress: true,
// If true; each slide will be pushed to the browser history
history: true,
// Loops the presentation, defaults to false
loop: false,
// Flags if mouse wheel navigation should be enabled
mouseWheel: false,
// UI style
theme: 'default', // default/neon
rollingLinks: false,
// Transition style
transition: 'default' // default/cube/page/concave/linear(2d)
});
</script>
</body>
</html>