Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Session 225 - Up and Running: Making a Great Im...

wwdcman
June 25, 2012
100

Session 225 - Up and Running: Making a Great Impression with Every Launch

wwdcman

June 25, 2012
Tweet

Transcript

  1. These are confidential sessions—please refrain from streaming, blogging, or taking

    pictures Making a great impression with every launch Session 225 Up and Running Jim Turner iOS Frameworks
  2. Ensures app launch time Exception Type: 00000020 Exception Codes: Highlighted

    Thread: 0 Application Specific Information: com.your.app.id failed to launch in time Elapsed total CPU time (seconds): 11.120 (user 1.840, system 9.280), 59% CPU Elapsed application CPU time (seconds): 2.160, 12% CPU I see what you did there Watchdog 0x8badf00d
  3. Put your UI on a diet Interface Loading •Eases creation

    •Allows experimentation •Reduces code
  4. Put your UI on a diet Interface Loading •Eases creation

    •Allows experimentation •Reduces code •However…
  5. Put your UI on a diet Interface Loading •Eases creation

    •Allows experimentation •Reduces code •However… ▪ Must instantiate entire object graph
  6. Put your UI on a diet Interface Loading •Eases creation

    •Allows experimentation •Reduces code •However… ▪ Must instantiate entire object graph ▪ Main queue
  7. Put your UI on a diet Interface Loading •Eases creation

    •Allows experimentation •Reduces code •However… ▪ Must instantiate entire object graph ▪ Main queue ▪ Side effects
  8. Time does not pass in The Waiting Place Network Communication

    •Undefined behavior •Blocking vs. non-blocking
  9. Time does not pass in The Waiting Place Network Communication

    •Undefined behavior •Blocking vs. non-blocking •Applies to all synchronous methods/behaviors
  10. Network Communication _XMLparser = [[NSXMLParser alloc] initWithContentsOfURL:…]; NSData *imgData =

    [NSData dataWithContentsOfURL:…]; UIImage *img = [UIImage imageWithData:imgData]; NSData *formResults = [NSURLConnection sendSynchronousRequest:req returningResponse:nil error:&error];
  11. Network Communication _XMLparser = [[NSXMLParser alloc] initWithContentsOfURL:…]; NSData *imgData =

    [NSData dataWithContentsOfURL:…]; UIImage *img = [UIImage imageWithData:imgData]; NSData *formResults = [NSURLConnection sendSynchronousRequest:req returningResponse:nil error:&error];
  12. Network Communication _XMLparser = [[NSXMLParser alloc] initWithContentsOfURL:…]; NSData *imgData =

    [NSData dataWithContentsOfURL:…]; UIImage *img = [UIImage imageWithData:imgData]; NSData *formResults = [NSURLConnection sendSynchronousRequest:req returningResponse:nil error:&error];
  13. Network Communication _XMLparser = [[NSXMLParser alloc] initWithContentsOfURL:…]; NSData *imgData =

    [NSData dataWithContentsOfURL:…]; UIImage *img = [UIImage imageWithData:imgData]; NSData *formResults = [NSURLConnection sendSynchronousRequest:req returningResponse:nil error:&error];
  14. Network Communication Downloads Current Info JSON Image Image Article Data

    Twitter [614 KB] [22 KB] [17.9 MB] [12.2 MB] [4.8 MB] [977 KB] Finished waiting… waiting… waiting… waiting… waiting…
  15. Network Communication Downloads Current Info JSON Image Image Article Data

    Twitter [614 KB] [22 KB] [17.9 MB] [12.2 MB] [4.8 MB] [977 KB] Finished waiting… waiting… waiting… waiting… waiting…
  16. Network Communication Downloads Current Info JSON Image Image Article Data

    Twitter [614 KB] [22 KB] [17.9 MB] [12.2 MB] [4.8 MB] [977 KB] Finished waiting… waiting… waiting… waiting… waiting… Main Queue
  17. Network Communication _XMLparser = [[NSXMLParser alloc] initWithContentsOfURL:…]; NSData *imgData =

    [NSData dataWithContentsOfURL:…]; UIImage *img = [UIImage imageWithData:imgData]; NSData *formResults = [NSURLConnection sendSynchronousRequest:req returningResponse:nil error:&error];
  18. Network Communication dispatch_async(serialQueue, ^{ _XMLparser = [[NSXMLParser alloc] initWithContentsOfURL:…]; NSData

    *imgData = [NSData dataWithContentsOfURL:…]; UIImage *img = [UIImage imageWithData:imgData]; NSData *formResults = [NSURLConnection sendSynchronousRequest:req returningResponse:nil error:&error]; });
  19. Network Communication dispatch_async(serialQueue, ^{ _XMLparser = [[NSXMLParser alloc] initWithContentsOfURL:…]; NSData

    *imgData = [NSData dataWithContentsOfURL:…]; UIImage *img = [UIImage imageWithData:imgData]; NSData *formResults = [NSURLConnection sendSynchronousRequest:req returningResponse:nil error:&error]; });
  20. Network Communication Downloads Current Info JSON Image Image Article Data

    Twitter [614 KB] [22 KB] [17.9 MB] [12.2 MB] [4.8 MB] [977 KB] Finished waiting… waiting… waiting… waiting… waiting… Main Queue
  21. Network Communication Downloads Current Info JSON Image Image Article Data

    Twitter [614 KB] [22 KB] [17.9 MB] [12.2 MB] [4.8 MB] [977 KB] Finished waiting… waiting… waiting… waiting… waiting… Main Queue
  22. Background Queue Network Communication Downloads Current Info JSON Image Image

    Article Data Twitter [614 KB] [22 KB] [17.9 MB] [12.2 MB] [4.8 MB] [977 KB] Finished waiting… waiting… waiting… waiting… waiting…
  23. Background Queue Network Communication Downloads Current Info JSON Image Image

    Article Data Twitter [614 KB] [22 KB] [17.9 MB] [12.2 MB] [4.8 MB] [977 KB] Finished waiting… waiting… waiting… waiting… waiting…
  24. Network Communication Downloads Current Info JSON Image Image Article Data

    Twitter [614 KB] [22 KB] [17.9 MB] [12.2 MB] [4.8 MB] [977 KB] Finished waiting… waiting… waiting… waiting… Background Queue
  25. Network Communication _XMLparser = [[NSXMLParser alloc] initWithContentsOfURL:…]; NSData *imgData =

    [NSData dataWithContentsOfURL:…]; UIImage *img = [UIImage imageWithData:imgData]; NSData *formResults = [NSURLConnection sendSynchronousRequest:req returningResponse:nil error:&error];
  26. dispatch_async(concurrentQueue, ^{ _XMLparser = [[NSXMLParser alloc] initWithContentsOfURL:…]; }); dispatch_async(concurrentQueue, ^{

    NSData *imgData = [NSData dataWithContentsOfURL:…]; UIImage *img = [UIImage imageWithData:imgData]; }); dispatch_async(concurrentQueue, ^{ NSData *formResults = [NSURLConnection sendSynchronousRequest:req returningResponse:nil error:&error]; }); Network Communication
  27. dispatch_async(concurrentQueue, ^{ _XMLparser = [[NSXMLParser alloc] initWithContentsOfURL:…]; }); dispatch_async(concurrentQueue, ^{

    NSData *imgData = [NSData dataWithContentsOfURL:…]; UIImage *img = [UIImage imageWithData:imgData]; }); dispatch_async(concurrentQueue, ^{ NSData *formResults = [NSURLConnection sendSynchronousRequest:req returningResponse:nil error:&error]; }); Network Communication
  28. Network Communication Downloads Current Info JSON Image Image Article Data

    Twitter [614 KB] [22 KB] [17.9 MB] [12.2 MB] [4.8 MB] [977 KB] Finished waiting… waiting… waiting… waiting… waiting… Main Queue
  29. Network Communication Downloads Current Info JSON Image Image Article Data

    Twitter [614 KB] [22 KB] [17.9 MB] [12.2 MB] [4.8 MB] [977 KB] Finished waiting… waiting… waiting… waiting… waiting… Main Queue
  30. Network Communication Downloads Current Info JSON Image Image Article Data

    Twitter [614 KB] [22 KB] [17.9 MB] [12.2 MB] [4.8 MB] [977 KB] Finished Processing Queue
  31. Network Communication Downloads Current Info JSON Image Image Article Data

    Twitter [614 KB] [22 KB] [17.9 MB] [12.2 MB] [4.8 MB] [977 KB] Finished Processing Queue
  32. Database Payload External Library •General processing •Need not block the

    app from launching •Parallelizable •Dependent on the network
  33. General Processing stockDatabase = [[DBManager alloc] initWithDatabaseName:@"Stocks"]; [stockDatabase updateTickerData]; [stockDatabase

    updateSymbols]; xmlParser = [[NSXMLParser alloc] initWithData:dataFromServer]; [xmlParser parse];
  34. General Processing dispatch_async(concurrentQueue, ^{ stockDatabase = [[DBManager alloc] initWithDatabaseName:@"Stocks"]; [stockDatabase

    updateTickerData]; [stockDatabase updateSymbols]; }); xmlParser = [[NSXMLParser alloc] initWithData:dataFromServer]; [xmlParser parse];
  35. General Processing dispatch_async(concurrentQueue, ^{ stockDatabase = [[DBManager alloc] initWithDatabaseName:@"Stocks"]; [stockDatabase

    updateTickerData]; [stockDatabase updateSymbols]; }); xmlParser = [[NSXMLParser alloc] initWithData:dataFromServer]; [xmlParser parse];
  36. General Processing dispatch_async(concurrentQueue, ^{ stockDatabase = [[DBManager alloc] initWithDatabaseName:@"Stocks"]; [stockDatabase

    updateTickerData]; [stockDatabase updateSymbols]; }); xmlParser = [[NSXMLParser alloc] initWithData:dataFromServer]; [xmlParser parse];
  37. General Processing _operationQueue = [[NSOperationQueue alloc] init]; [_operationQueue setName:@”Processing Queue”];

    NSOperation *networkOp = ... Processing Queue Network Operation Network Operation Network Operation
  38. Parse XML General Processing _operationQueue = [[NSOperationQueue alloc] init]; [_operationQueue

    setName:@”Processing Queue”]; NSOperation *networkOp = ... NSBlockOperation *xmlOp = [NSBlockOperation blockOperationWithBlock:^{...}]; Processing Queue Network Operation Network Operation Network Operation
  39. Parse XML General Processing _operationQueue = [[NSOperationQueue alloc] init]; [_operationQueue

    setName:@”Processing Queue”]; NSOperation *networkOp = ... NSBlockOperation *xmlOp = [NSBlockOperation blockOperationWithBlock:^{...}]; [xmlOp addDependency:networkOp]; Processing Queue Network Operation Network Operation Network Operation
  40. Parse XML General Processing _operationQueue = [[NSOperationQueue alloc] init]; [_operationQueue

    setName:@”Processing Queue”]; NSOperation *networkOp = ... NSBlockOperation *xmlOp = [NSBlockOperation blockOperationWithBlock:^{...}]; [xmlOp addDependency:networkOp]; [_operationQueue addOperation:xmlOp]; Processing Queue Network Operation Network Operation Network Operation
  41. General Processing Processing Queue Network Operation Network Operation Network Operation

    Parse XML _operationQueue = [[NSOperationQueue alloc] init]; [_operationQueue setName:@”Processing Queue”]; NSOperation *networkOp = ... NSBlockOperation *xmlOp = [NSBlockOperation blockOperationWithBlock:^{...}]; [xmlOp addDependency:networkOp]; [_operationQueue addOperation:xmlOp];
  42. General Processing Processing Queue Network Operation Network Operation Parse XML

    _operationQueue = [[NSOperationQueue alloc] init]; [_operationQueue setName:@”Processing Queue”]; NSOperation *networkOp = ... NSBlockOperation *xmlOp = [NSBlockOperation blockOperationWithBlock:^{...}]; [xmlOp addDependency:networkOp]; [_operationQueue addOperation:xmlOp];
  43. Network Operation General Processing Processing Queue Network Operation Parse XML

    _operationQueue = [[NSOperationQueue alloc] init]; [_operationQueue setName:@”Processing Queue”]; NSOperation *networkOp = ... NSBlockOperation *xmlOp = [NSBlockOperation blockOperationWithBlock:^{...}]; [xmlOp addDependency:networkOp]; [_operationQueue addOperation:xmlOp];
  44. Network Operation General Processing Processing Queue Network Operation Parse XML

    Slooow... _operationQueue = [[NSOperationQueue alloc] init]; [_operationQueue setName:@”Processing Queue”]; NSOperation *networkOp = ... NSBlockOperation *xmlOp = [NSBlockOperation blockOperationWithBlock:^{...}]; [xmlOp addDependency:networkOp]; [_operationQueue addOperation:xmlOp];
  45. Network Operation General Processing Processing Queue Network Operation Parse XML

    Slooow... Payload _operationQueue = [[NSOperationQueue alloc] init]; [_operationQueue setName:@”Processing Queue”]; NSOperation *networkOp = ... NSBlockOperation *xmlOp = [NSBlockOperation blockOperationWithBlock:^{...}]; [xmlOp addDependency:networkOp]; [_operationQueue addOperation:xmlOp];
  46. General Processing Processing Queue Network Operation Parse XML Slooow... Payload

    _operationQueue = [[NSOperationQueue alloc] init]; [_operationQueue setName:@”Processing Queue”]; NSOperation *networkOp = ... NSBlockOperation *xmlOp = [NSBlockOperation blockOperationWithBlock:^{...}]; [xmlOp addDependency:networkOp]; [_operationQueue addOperation:xmlOp];
  47. General Processing Processing Queue Network Operation Parse XML Slooow... _operationQueue

    = [[NSOperationQueue alloc] init]; [_operationQueue setName:@”Processing Queue”]; NSOperation *networkOp = ... NSBlockOperation *xmlOp = [NSBlockOperation blockOperationWithBlock:^{...}]; [xmlOp addDependency:networkOp]; [_operationQueue addOperation:xmlOp];
  48. General Processing Processing Queue Network Operation Parse XML Slooow... _operationQueue

    = [[NSOperationQueue alloc] init]; [_operationQueue setName:@”Processing Queue”]; NSOperation *networkOp = ... NSBlockOperation *xmlOp = [NSBlockOperation blockOperationWithBlock:^{...}]; [xmlOp addDependency:networkOp]; [_operationQueue addOperation:xmlOp];
  49. General Processing Processing Queue _operationQueue = [[NSOperationQueue alloc] init]; [_operationQueue

    setName:@”Processing Queue”]; NSOperation *networkOp = ... NSBlockOperation *xmlOp = [NSBlockOperation blockOperationWithBlock:^{...}]; [xmlOp addDependency:networkOp]; [_operationQueue addOperation:xmlOp];
  50. ?

  51. Highest Rated Popular Patti 6/5/12 Most Creative Creative Carl 6/5/12

    Least Popular Sad Samantha 6/5/12 Top Trending Trendy Trent 6/5/12 ? ? ? ?
  52. Highest Rated Popular Patti 6/5/12 Most Creative Creative Carl 6/5/12

    Least Popular Sad Samantha 6/5/12 Top Trending Trendy Trent 6/5/12 ? ? ? ? Highest Rated Popular Patti 6/5/12 Wow L. Micarel 6/3/12 Least Popular Sad Samantha 6/5/12 Frisbee N. Jones 6/1/12 ? ?
  53. Jump! W. Joseph 6/5/12 Wow L. Micarel 6/3/12 Seine J.

    Johnson 5/27/12 Frisbee N. Jones 6/1/12 Highest Rated Popular Patti 6/5/12 Most Creative Creative Carl 6/5/12 Least Popular Sad Samantha 6/5/12 Top Trending Trendy Trent 6/5/12 ? ? ? ? Highest Rated Popular Patti 6/5/12 Wow L. Micarel 6/3/12 Least Popular Sad Samantha 6/5/12 Frisbee N. Jones 6/1/12 ? ?
  54. State Restoration What Remains •Save and restore application state •New

    delegate method application:didFinishLaunchingWithOptions:
  55. State Restoration What Remains •Save and restore application state •New

    delegate method application:willFinishLaunchingWithOptions:
  56. State Restoration What Remains •Save and restore application state •New

    delegate method application:willFinishLaunchingWithOptions: Saving and Restoring Application State on iOS Russian Hill Thursday 3:15PM
  57. Wrap Up •“Do I need this here?” •Unneighborly network •Don’t

    abuse dispatch_async •What can you provide immediately?
  58. More Information Jake Behrens UI Frameworks Evangelist [email protected] Documentation UIApplicationDelegate

    protocol Storyboards NSOperation and NSOperationQueue State Restoration http://developer.apple.com/ Apple Developer Forums http://devforums.apple.com