Design Patterns for
Mobile Apps
Thursday, June 13, 13
InfoQ.com: News & Community Site
• 750,000 unique visitors/month
• Published in 4 languages (English, Chinese, Japanese an...
Presented at QCon New York
www.qconnewyork.com
Purpose of QCon
- to empower software development by facilitating the sprea...
Cocoa Design Patterns
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
NSBrief
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Hawtness
Thursday, June 13, 13
853 apps per day
148apps.biz
January 2013
Thursday, June 13, 13
133 games per day
148apps.biz
January 2013
Thursday, June 13, 13
Quality Takes Time
Thursday, June 13, 13
Time == $$$
Thursday, June 13, 13
Time Tested Solutions
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Let’s Build a
Mobile App
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
View
Controller
Model
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
MVC
Thursday, June 13, 13
Model View Controller
Thursday, June 13, 13
Model View Controller
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
@interface Post : _Post
+ (id) postWithId:(NSNumber *)postId;
- (void) downloadAttachments;
@end
Thursday, June 13, 13
Model View Controller
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Model View Controller
Thursday, June 13, 13
?
Thursday, June 13, 13
MVC
Thursday, June 13, 13
MVC
Thursday, June 13, 13
View
ViewController
Model
View
ViewController
View
ViewController
Thursday, June 13, 13
View
ViewController
Model
View
ViewController
View
ViewController
Thursday, June 13, 13
View
ViewController
Model
Thursday, June 13, 13
MVC can be composed of
MVC (UITextView for
example)
View
ViewController
Model
Thursday, June 13, 13
MVC can be composed of
MVC (UITextView for
example)
Database
Visual Control
Network
App.net
View
ViewController
Model
Thur...
DatabaseVisual Control
Network App.net
ViewController
Thursday, June 13, 13
DatabaseVisual Control
Network App.net
ViewController
Thursday, June 13, 13
Thursday, June 13, 13
AppDelegate
Thursday, June 13, 13
AppDelegate
RootViewController
Thursday, June 13, 13
AppDelegate
RootViewController
Thursday, June 13, 13
AppDelegate
RootViewController
ViewController
Thursday, June 13, 13
AppDelegate
RootViewController
ViewController
ViewController
Thursday, June 13, 13
AppDelegate
RootViewController
ViewController
ViewController
ViewController
ViewController
Thursday, June 13, 13
AppDelegate
RootViewController
ViewController
ViewController
ViewController
ViewController
ViewController
ViewController
V...
AppDelegate
RootViewController
ViewController
ViewController
ViewController
ViewController
ViewController
ViewController
V...
AppDelegate
RootViewController
ViewController
ViewController
ViewController
ViewController
ViewController
ViewController
V...
AppDelegate
RootViewController
ViewController
ViewController
ViewController
ViewController
Thursday, June 13, 13
AppDelegate
RootViewController
ViewController
ViewController
ViewController
ViewController
App.net
Thursday, June 13, 13
(MyAppDelegate *)[[UIApplication
sharedApplication] delegate]
Thursday, June 13, 13
#define sharedDelegate 
(MyAppDelegate *)[[UIApplication sharedApplication] delegate]
Thursday, June 13, 13
AppDelegate
RootViewController
ViewController
ViewController
ViewController
ViewController
App.net
Thursday, June 13, 13
AppDelegate
RootViewController
ViewController
ViewController
ViewController
ViewController
App.net
message
Thursday, June ...
AppDelegate
RootViewController
ViewController
ViewController
ViewController
ViewController
App.net
message
Thursday, June ...
AppDelegate
RootViewController
ViewController
ViewController
ViewController
ViewController
App.net
message
Thursday, June ...
AppDelegate
RootViewController
ViewController
ViewController
ViewController
ViewController
App.net
message
Thursday, June ...
AppDelegate
RootViewController
ViewController
ViewController
ViewController
ViewController
App.netmessage
Thursday, June 1...
AppDelegate
RootViewController
ViewController
ViewController
ViewController
ViewController
App.netmessage
Thursday, June 1...
Chain of Responsibility
Pause here more, explain
more :
What
When to use
Why
Thursday, June 13, 13
Responder Chain
Thursday, June 13, 13
[[UIApplication
sharedApplication]
sendAction:to:from:forEvent:]
Thursday, June 13, 13
@implementation UIView
(FindAndResignFirstResponder)
- (BOOL)findAndResignFirstResponder
{
if ([self isFirstResponder]) {
...
while ([obj retainCount]) [obj release];
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
[[UIApplication sharedApplication]
sendAction:@selector(resignFirstResponder)
to:nil
from:self
forEvent:nil]
Thursday, Jun...
[[UIApplication sharedApplication]
sendAction:@selector(resignFirstResponder)
to:nil
from:self
forEvent:nil]
Thursday, Jun...
- (void)viewDidAppear:
Thursday, June 13, 13
AppDelegate
RVC
VC
View
Thursday, June 13, 13
AppDelegate
RVC
VC
View
Thursday, June 13, 13
AppDelegate
RVC
VC
View
VC
View
Thursday, June 13, 13
AppDelegate
RVC
VC
View
VC
View
Thursday, June 13, 13
AppDelegate
RVC
VC
View
VC
View
Thursday, June 13, 13
Command
Thursday, June 13, 13
Thursday, June 13, 13
- (void)viewDidLoad {
[super viewDidLoad];
// Setting Up Table View
self.tableView = [[UITableView alloc] initWithFrame:CG...
- (void)viewDidLoad {
[super viewDidLoad];
// Setting Up Table View
self.tableView = [[UITableView alloc] initWithFrame:CG...
// Initializing Data Source
self.movies = [[NSArray alloc] init];
NSURL *url = [[NSURL alloc] initWithString:@"http://itun...
// Initializing Data Source
self.movies = [[NSArray alloc] init];
NSURL *url = [[NSURL alloc] initWithString:@"http://itun...
^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
self.movies = [JSON objectForKey:@"results"];
[self.activ...
ADN Service
Thursday, June 13, 13
ADN Service
https://alpha-api.app.net/stream/0/posts/stream
Thursday, June 13, 13
ADN Service
https://alpha-api.app.net/stream/0/posts/stream
Thursday, June 13, 13
ADN Service
https://alpha-api.app.net/stream/0/posts/stream
POST:
include_reposters=1&include_annotations=1&incl
ude_muted...
ADN Service
Get Personal Stream
Thursday, June 13, 13
ADN Service
Get Personal Stream
include_reposters
include_muted
include_annotations
include_starred_by
Thursday, June 13, ...
ADN Service
Get Personal Stream
Thursday, June 13, 13
ADN Service
Get Personal Stream
Thursday, June 13, 13
ADN Service
Get Personal Stream
@property (nonatomic, assign) BOOL includeReposters
@property (nonatomic, assign) BOOL inc...
ADN Service
@class ADNRetrievePersonalStreamCommand : ADNCommand
@property (nonatomic, assign) BOOL includeReposters
@prop...
ADN Service
@class ADNRetrievePersonalStreamCommand : ADNCommand
@property (nonatomic, assign) BOOL includeReposters
@prop...
Get Personal Stream
ADN Service
Thursday, June 13, 13
Get Personal StreamADN Service
Thursday, June 13, 13
Command
Thursday, June 13, 13
ADNCommand
Thursday, June 13, 13
ADNCommand
Thursday, June 13, 13
ADNPersonalStreamCommand
ADNCommand
Thursday, June 13, 13
ADNPersonalStreamCommand
ADNCommand
Thursday, June 13, 13
ADNPersonalStreamCommand
ADNCommand
Thursday, June 13, 13
ADNPersonalStreamCommand
ADNPostStatusCommand
ADNRetrieveChannelCommand
ADNUserLookupCommand
ADNCommand
Thursday, June 13,...
Template
Thursday, June 13, 13
Thursday, June 13, 13
//AppDelegate.h
@interface AppDelegate : UIResponder<UIApplicationDelegate>
@property (nonatomic, strong, readwrite) IBOut...
@interface WebService : UIResponder
@property (nonatomic, copy, readonly) NSURL *baseURL;
@property (nonatomic, strong, re...
@interface WebService (Commands)
- (IBAction) loginToService;
- (IBAction) logoutFromService;
- (IBAction) retrieveUsersPe...
- (void) loginToService
{
WebServiceLoginCommand *command = [WebServiceLoginCommand
commandWithService:self];
command.toke...
- (NSString *)username;
{
return [self textValueForCellAtIndexPath:[NSIndexPath
indexPathForRow:0 inSection:0]];
}
- (NSSt...
- (void) sendCommand:(WebServiceCommand *)command;
{
BOOL commandVerified = [self verifyCommand:command];
if (!commandVeri...
- (void) sendCommand:(WebServiceCommand *)command;
{
BOOL commandVerified = [self verifyCommand:command];
if (!commandVeri...
- (void) sendCommand:(WebServiceCommand *)command;
{
BOOL commandVerified = [self verifyCommand:command];
if (!commandVeri...
[self.delegate displayMessage:@"No Internet Connection"];
DDLogInfo(@"Not connected to a network");
Thursday, June 13, 13
AFHTTPRequestOperation *operation = [command
createRequestOperation];
[self.httpClient enqueueHTTPRequestOperation:operati...
ommand
Object
WebService Object
Our App
Actual
Service
Thursday, June 13, 13
WebService Object
Our App HTTP Requ
Actual
Service
Thursday, June 13, 13
HTTP
Respons
WebService Object
Our App
Actual
Service
Thursday, June 13, 13
WebService Object
ble ObjectOur App
Actual
Service
Thursday, June 13, 13
Usable Object
Needs to be more clear
Thursday, June 13, 13
Needs to be more clear
Usable Object
Thursday, June 13, 13
Thursday, June 13, 13
NSFetchedResultsController
Thursday, June 13, 13
- (void) loadUserStream;
{
self.results = [StreamEvent MR_fetchAllSortedBy:StreamEvent.createdDate
ascending:YES
withPredi...
- (void) loadUserStream;
{
self.results = [StreamEvent MR_fetchAllSortedBy:StreamEvent.createdDate
ascending:YES
withPredi...
NSFetchedResultsControllerDelegate
Thursday, June 13, 13
Delegation
Thursday, June 13, 13
AbstractTemplate
ConcreteTemplate
Thursday, June 13, 13
AbstractTemplate
ConcreteTemplate
Thursday, June 13, 13
AbstractTemplate ConcreteTemplate
Thursday, June 13, 13
AbstractTemplate ConcreteTemplate
Thursday, June 13, 13
- (void)controller:(NSFetchedResultsController *)controller
didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)theInd...
switch(type)
{
case NSFetchedResultsChangeInsert:
[tableView insertRowsAtIndexPaths:@[theIndexPath]
withRowAnimation:UITab...
Observer
Last steps from
controller to view with
observer pattern
Thursday, June 13, 13
Model
Controller
View
Thursday, June 13, 13
Composite
Command
Mediator
Strategy
Observer
Thursday, June 13, 13
Model
ViewController
View
Thursday, June 13, 13
Model
ViewController
View
Thursday, June 13, 13
Model
ViewController
View
Thursday, June 13, 13
Model
ViewController
View
Thursday, June 13, 13
Model
ViewController
View
Thursday, June 13, 13
Touch Interface
View
ViewController
App.net App.net
AppDelegate CoreData
Thursday, June 13, 13
Touch Interface
View
ViewController
App.net App.net
AppDelegate CoreData
Thursday, June 13, 13
Touch Interface
View
ViewController
App.net App.net
AppDelegate CoreData
Thursday, June 13, 13
Touch Interface
View
ViewController
App.net App.net
AppDelegate CoreData
Thursday, June 13, 13
Touch Interface
View
ViewController
App.net App.net
AppDelegate CoreData
Thursday, June 13, 13
Touch Interface
View
ViewController
App.net App.net
AppDelegate CoreData
Thursday, June 13, 13
Touch Interface
View
ViewController
App.net App.net
AppDelegate CoreData
Thursday, June 13, 13
Touch Interface
View
ViewController
App.net App.net
AppDelegate CoreData
Thursday, June 13, 13
Touch Interface
View
ViewController
App.net App.net
AppDelegate CoreData
Thursday, June 13, 13
Touch Interface
View
ViewController
App.net App.net
AppDelegate CoreData
Thursday, June 13, 13
Touch Interface
View
ViewController
App.net App.net
AppDelegate CoreData
Thursday, June 13, 13
Touch Interface
View
ViewController
App.net App.net
AppDelegate CoreData
Thursday, June 13, 13
Pattern Abuse
Thursday, June 13, 13
Factory
Thursday, June 13, 13
Abstract Factories
Thursday, June 13, 13
Two-Stage Creation
Thursday, June 13, 13
[[MyClass alloc] init]
Thursday, June 13, 13
NSClassFromString
Thursday, June 13, 13
[NSClassFromString(@”MyClass”) alloc] init]
Thursday, June 13, 13
Singletons
More explanation in
slides
Thursday, June 13, 13
Singletons
More explanation in
slides
Thursday, June 13, 13
More explanation in
slides
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Singleton
ViewController AppDelegate
Thursday, June 13, 13
Singleton
ViewController AppDelegate
Thursday, June 13, 13
Singleton
ViewController
AppDelegate
Model ObjectNetwork
Web Service
Thursday, June 13, 13
Singleton
ViewController
AppDelegate
Model ObjectNetwork
Web Service
Thursday, June 13, 13
Singleton
ViewController
AppDelegate
Model ObjectNetwork
Web Service
Thursday, June 13, 13
Singleton
ViewController
AppDelegate
Model ObjectNetwork
Web ServiceWeb ServiceWeb Service
ViewControllerViewControllerVie...
Singleton
Thursday, June 13, 13
Singleton
Thursday, June 13, 13
AppDelegate
Thursday, June 13, 13
Singleton Manager
AppDelegate
Thursday, June 13, 13
Singleton Manager
AppDelegate
Singleton
Singleton
Singleton
Thursday, June 13, 13
Singleton ManagerAppDelegate
-instanceForClass:[Singleton class]
Thursday, June 13, 13
Singleton ManagerAppDelegate
Thursday, June 13, 13
Singleton ManagerAppDelegate
-destroyInstanceForClass:[Singleton class]
Thursday, June 13, 13
Singleton ManagerAppDelegate
Thursday, June 13, 13
SingletonSingleton ManagerAppDelegate
ViewController
Thursday, June 13, 13
Singleton
Singleton ManagerAppDelegate
ViewController
Thursday, June 13, 13
ServiceLocator
Thursday, June 13, 13
Classes are objects too...
Thursday, June 13, 13
@property Class dateCreator;
Thursday, June 13, 13
[self.dateCreator date];
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
Thursday, June 13, 13
It was important, his
father said, to craft the
backs of cabinets and
fences properly, even
though they were hidden.
Steve...
“He loved doing things
right. He even cared
about the look of the
parts you couldn’t see.”
- Steve Jobs
Thursday, June 13,...
saul@magicalpanda.com
Thursday, June 13, 13
Upcoming SlideShare
Loading in...5
×

Design Patterns for Mobile Applications

859

Published on

Video and slides synchronized, mp3 and slide download available at http://bit.ly/19skk3A.

Saul Mora discusses using some of the patterns from the Design Pattern book today, and applying patterns in a multicore world.Filmed at qconnewyork.com.

Saul Mora is an active member of the Cocoa developer community and contributes by blogging, producing NSBrief (a developer podcast, http://nsbrief.com), contributing to open source projects, and helping to teach others about the wonders and methods of developing applications.

Published in: Technology

Transcript of "Design Patterns for Mobile Applications"

  1. 1. Design Patterns for Mobile Apps Thursday, June 13, 13
  2. 2. InfoQ.com: News & Community Site • 750,000 unique visitors/month • Published in 4 languages (English, Chinese, Japanese and Brazilian Portuguese) • Post content from our QCon conferences • News 15-20 / week • Articles 3-4 / week • Presentations (videos) 12-15 / week • Interviews 2-3 / week • Books 1 / month Watch the video with slide synchronization on InfoQ.com! http://www.infoq.com/presentations /mobile-design-patterns
  3. 3. Presented at QCon New York www.qconnewyork.com Purpose of QCon - to empower software development by facilitating the spread of knowledge and innovation Strategy - practitioner-driven conference designed for YOU: influencers of change and innovation in your teams - speakers and topics driving the evolution and innovation - connecting and catalyzing the influencers and innovators Highlights - attended by more than 12,000 delegates since 2007 - held in 9 cities worldwide
  4. 4. Cocoa Design Patterns Thursday, June 13, 13
  5. 5. Thursday, June 13, 13
  6. 6. Thursday, June 13, 13
  7. 7. NSBrief Thursday, June 13, 13
  8. 8. Thursday, June 13, 13
  9. 9. Thursday, June 13, 13
  10. 10. Thursday, June 13, 13
  11. 11. Thursday, June 13, 13
  12. 12. Thursday, June 13, 13
  13. 13. Thursday, June 13, 13
  14. 14. Thursday, June 13, 13
  15. 15. Thursday, June 13, 13
  16. 16. Thursday, June 13, 13
  17. 17. Thursday, June 13, 13
  18. 18. Thursday, June 13, 13
  19. 19. Thursday, June 13, 13
  20. 20. Thursday, June 13, 13
  21. 21. Thursday, June 13, 13
  22. 22. Thursday, June 13, 13
  23. 23. Thursday, June 13, 13
  24. 24. Thursday, June 13, 13
  25. 25. Hawtness Thursday, June 13, 13
  26. 26. 853 apps per day 148apps.biz January 2013 Thursday, June 13, 13
  27. 27. 133 games per day 148apps.biz January 2013 Thursday, June 13, 13
  28. 28. Quality Takes Time Thursday, June 13, 13
  29. 29. Time == $$$ Thursday, June 13, 13
  30. 30. Time Tested Solutions Thursday, June 13, 13
  31. 31. Thursday, June 13, 13
  32. 32. Thursday, June 13, 13
  33. 33. Thursday, June 13, 13
  34. 34. Thursday, June 13, 13
  35. 35. Thursday, June 13, 13
  36. 36. Thursday, June 13, 13
  37. 37. Let’s Build a Mobile App Thursday, June 13, 13
  38. 38. Thursday, June 13, 13
  39. 39. Thursday, June 13, 13
  40. 40. Thursday, June 13, 13
  41. 41. Thursday, June 13, 13
  42. 42. Thursday, June 13, 13
  43. 43. Thursday, June 13, 13
  44. 44. Thursday, June 13, 13
  45. 45. View Controller Model Thursday, June 13, 13
  46. 46. Thursday, June 13, 13
  47. 47. Thursday, June 13, 13
  48. 48. MVC Thursday, June 13, 13
  49. 49. Model View Controller Thursday, June 13, 13
  50. 50. Model View Controller Thursday, June 13, 13
  51. 51. Thursday, June 13, 13
  52. 52. Thursday, June 13, 13
  53. 53. @interface Post : _Post + (id) postWithId:(NSNumber *)postId; - (void) downloadAttachments; @end Thursday, June 13, 13
  54. 54. Model View Controller Thursday, June 13, 13
  55. 55. Thursday, June 13, 13
  56. 56. Thursday, June 13, 13
  57. 57. Model View Controller Thursday, June 13, 13
  58. 58. ? Thursday, June 13, 13
  59. 59. MVC Thursday, June 13, 13
  60. 60. MVC Thursday, June 13, 13
  61. 61. View ViewController Model View ViewController View ViewController Thursday, June 13, 13
  62. 62. View ViewController Model View ViewController View ViewController Thursday, June 13, 13
  63. 63. View ViewController Model Thursday, June 13, 13
  64. 64. MVC can be composed of MVC (UITextView for example) View ViewController Model Thursday, June 13, 13
  65. 65. MVC can be composed of MVC (UITextView for example) Database Visual Control Network App.net View ViewController Model Thursday, June 13, 13
  66. 66. DatabaseVisual Control Network App.net ViewController Thursday, June 13, 13
  67. 67. DatabaseVisual Control Network App.net ViewController Thursday, June 13, 13
  68. 68. Thursday, June 13, 13
  69. 69. AppDelegate Thursday, June 13, 13
  70. 70. AppDelegate RootViewController Thursday, June 13, 13
  71. 71. AppDelegate RootViewController Thursday, June 13, 13
  72. 72. AppDelegate RootViewController ViewController Thursday, June 13, 13
  73. 73. AppDelegate RootViewController ViewController ViewController Thursday, June 13, 13
  74. 74. AppDelegate RootViewController ViewController ViewController ViewController ViewController Thursday, June 13, 13
  75. 75. AppDelegate RootViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController Thursday, June 13, 13
  76. 76. AppDelegate RootViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController Thursday, June 13, 13
  77. 77. AppDelegate RootViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewControlle wController iewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewControllerViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController wController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewControlle ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewCo ViewContr ViewController ViewCon ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController ViewController Thursday, June 13, 13
  78. 78. AppDelegate RootViewController ViewController ViewController ViewController ViewController Thursday, June 13, 13
  79. 79. AppDelegate RootViewController ViewController ViewController ViewController ViewController App.net Thursday, June 13, 13
  80. 80. (MyAppDelegate *)[[UIApplication sharedApplication] delegate] Thursday, June 13, 13
  81. 81. #define sharedDelegate (MyAppDelegate *)[[UIApplication sharedApplication] delegate] Thursday, June 13, 13
  82. 82. AppDelegate RootViewController ViewController ViewController ViewController ViewController App.net Thursday, June 13, 13
  83. 83. AppDelegate RootViewController ViewController ViewController ViewController ViewController App.net message Thursday, June 13, 13
  84. 84. AppDelegate RootViewController ViewController ViewController ViewController ViewController App.net message Thursday, June 13, 13
  85. 85. AppDelegate RootViewController ViewController ViewController ViewController ViewController App.net message Thursday, June 13, 13
  86. 86. AppDelegate RootViewController ViewController ViewController ViewController ViewController App.net message Thursday, June 13, 13
  87. 87. AppDelegate RootViewController ViewController ViewController ViewController ViewController App.netmessage Thursday, June 13, 13
  88. 88. AppDelegate RootViewController ViewController ViewController ViewController ViewController App.netmessage Thursday, June 13, 13
  89. 89. Chain of Responsibility Pause here more, explain more : What When to use Why Thursday, June 13, 13
  90. 90. Responder Chain Thursday, June 13, 13
  91. 91. [[UIApplication sharedApplication] sendAction:to:from:forEvent:] Thursday, June 13, 13
  92. 92. @implementation UIView (FindAndResignFirstResponder) - (BOOL)findAndResignFirstResponder { if ([self isFirstResponder]) { [self resignFirstResponder]; return YES; } for (UIView *subView in [self subviews]) { if ([subView findAndResignFirstResponder]) return YES; } return NO; } @end Thursday, June 13, 13
  93. 93. while ([obj retainCount]) [obj release]; Thursday, June 13, 13
  94. 94. Thursday, June 13, 13
  95. 95. Thursday, June 13, 13
  96. 96. [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:self forEvent:nil] Thursday, June 13, 13
  97. 97. [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:self forEvent:nil] Thursday, June 13, 13
  98. 98. - (void)viewDidAppear: Thursday, June 13, 13
  99. 99. AppDelegate RVC VC View Thursday, June 13, 13
  100. 100. AppDelegate RVC VC View Thursday, June 13, 13
  101. 101. AppDelegate RVC VC View VC View Thursday, June 13, 13
  102. 102. AppDelegate RVC VC View VC View Thursday, June 13, 13
  103. 103. AppDelegate RVC VC View VC View Thursday, June 13, 13
  104. 104. Command Thursday, June 13, 13
  105. 105. Thursday, June 13, 13
  106. 106. - (void)viewDidLoad { [super viewDidLoad]; // Setting Up Table View self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, self.view.bounds.size.height) style:UITableViewStylePlain]; self.tableView.dataSource = self; self.tableView.delegate = self; self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; self.tableView.hidden = YES; [self.view addSubview:self.tableView]; // Setting Up Activity Indicator View self.activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; self.activityIndicatorView.hidesWhenStopped = YES; self.activityIndicatorView.center = self.view.center; [self.view addSubview:self.activityIndicatorView]; [self.activityIndicatorView startAnimating]; // Initializing Data Source self.movies = [[NSArray alloc] init]; NSURL *url = [[NSURL alloc] initWithString:@"http://itunes.apple.com/search?term=harry&country=us&entity=movie"]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { self.movies = [JSON objectForKey:@"results"]; [self.activityIndicatorView stopAnimating]; [self.tableView setHidden:NO]; [self.tableView reloadData]; } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) { NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo); }]; [operation start]; } Thursday, June 13, 13
  107. 107. - (void)viewDidLoad { [super viewDidLoad]; // Setting Up Table View self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, self.view.bounds.size.height) style:UITableViewStylePlain]; self.tableView.dataSource = self; self.tableView.delegate = self; self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; self.tableView.hidden = YES; [self.view addSubview:self.tableView]; // Setting Up Activity Indicator View self.activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; self.activityIndicatorView.hidesWhenStopped = YES; self.activityIndicatorView.center = self.view.center; [self.view addSubview:self.activityIndicatorView]; [self.activityIndicatorView startAnimating]; // Initializing Data Source self.movies = [[NSArray alloc] init]; NSURL *url = [[NSURL alloc] initWithString:@"http://itunes.apple.com/search?term=harry&country=us&entity=movie"]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { self.movies = [JSON objectForKey:@"results"]; [self.activityIndicatorView stopAnimating]; [self.tableView setHidden:NO]; [self.tableView reloadData]; } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) { NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo); }]; [operation start]; } Thursday, June 13, 13
  108. 108. // Initializing Data Source self.movies = [[NSArray alloc] init]; NSURL *url = [[NSURL alloc] initWithString:@"http://itunes.apple.com/search? term=harry&country=us&entity=movie"]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { self.movies = [JSON objectForKey:@"results"]; [self.activityIndicatorView stopAnimating]; [self.tableView setHidden:NO]; [self.tableView reloadData]; } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) { NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo); }]; [operation start]; Thursday, June 13, 13
  109. 109. // Initializing Data Source self.movies = [[NSArray alloc] init]; NSURL *url = [[NSURL alloc] initWithString:@"http://itunes.apple.com/search? term=harry&country=us&entity=movie"]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { self.movies = [JSON objectForKey:@"results"]; [self.activityIndicatorView stopAnimating]; [self.tableView setHidden:NO]; [self.tableView reloadData]; } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) { NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo); }]; [operation start]; Thursday, June 13, 13
  110. 110. ^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { self.movies = [JSON objectForKey:@"results"]; [self.activityIndicatorView stopAnimating]; [self.tableView setHidden:NO]; [self.tableView reloadData]; } Thursday, June 13, 13
  111. 111. ADN Service Thursday, June 13, 13
  112. 112. ADN Service https://alpha-api.app.net/stream/0/posts/stream Thursday, June 13, 13
  113. 113. ADN Service https://alpha-api.app.net/stream/0/posts/stream Thursday, June 13, 13
  114. 114. ADN Service https://alpha-api.app.net/stream/0/posts/stream POST: include_reposters=1&include_annotations=1&incl ude_muted=0&include_starred_by=1 Thursday, June 13, 13
  115. 115. ADN Service Get Personal Stream Thursday, June 13, 13
  116. 116. ADN Service Get Personal Stream include_reposters include_muted include_annotations include_starred_by Thursday, June 13, 13
  117. 117. ADN Service Get Personal Stream Thursday, June 13, 13
  118. 118. ADN Service Get Personal Stream Thursday, June 13, 13
  119. 119. ADN Service Get Personal Stream @property (nonatomic, assign) BOOL includeReposters @property (nonatomic, assign) BOOL includeAnnotations @property (nonatomic, assign) BOOL includeStarredBy @property (nonatomic, assign) BOOL includeMuted Thursday, June 13, 13
  120. 120. ADN Service @class ADNRetrievePersonalStreamCommand : ADNCommand @property (nonatomic, assign) BOOL includeReposters @property (nonatomic, assign) BOOL includeAnnotations @property (nonatomic, assign) BOOL includeStarredBy @property (nonatomic, assign) BOOL includeMuted Thursday, June 13, 13
  121. 121. ADN Service @class ADNRetrievePersonalStreamCommand : ADNCommand @property (nonatomic, assign) BOOL includeReposters @property (nonatomic, assign) BOOL includeAnnotations @property (nonatomic, assign) BOOL includeStarredBy @property (nonatomic, assign) BOOL includeMuted @property (nonatomic, copy) NSURL *baseURL; @class ADNService : UIResponder Thursday, June 13, 13
  122. 122. Get Personal Stream ADN Service Thursday, June 13, 13
  123. 123. Get Personal StreamADN Service Thursday, June 13, 13
  124. 124. Command Thursday, June 13, 13
  125. 125. ADNCommand Thursday, June 13, 13
  126. 126. ADNCommand Thursday, June 13, 13
  127. 127. ADNPersonalStreamCommand ADNCommand Thursday, June 13, 13
  128. 128. ADNPersonalStreamCommand ADNCommand Thursday, June 13, 13
  129. 129. ADNPersonalStreamCommand ADNCommand Thursday, June 13, 13
  130. 130. ADNPersonalStreamCommand ADNPostStatusCommand ADNRetrieveChannelCommand ADNUserLookupCommand ADNCommand Thursday, June 13, 13
  131. 131. Template Thursday, June 13, 13
  132. 132. Thursday, June 13, 13
  133. 133. //AppDelegate.h @interface AppDelegate : UIResponder<UIApplicationDelegate> @property (nonatomic, strong, readwrite) IBOutlet UIWindow *window; @property (nonatomic, strong, readonly) WebService *webService; @end //AppDelegate.m - (UIResponder *)nextResponder; { return self.webService; } Thursday, June 13, 13
  134. 134. @interface WebService : UIResponder @property (nonatomic, copy, readonly) NSURL *baseURL; @property (nonatomic, strong, readonly) TokenStorage *tokenStorage; //..more properties - (id) initWithBaseURL:(NSURL *)baseURL; - (void) sendCommand:(WebServiceCommand *)command; - (void) presentMessageFromCommand:(NSString *)message; - (BOOL) isAuthenticated; - (BOOL) performAction:(SEL)action from:(id)sender; - (BOOL) performAction:(SEL)action from:(id)sender parameters: (NSDictionary *)parameters; + (BOOL) isNetworkReachable; @end Thursday, June 13, 13
  135. 135. @interface WebService (Commands) - (IBAction) loginToService; - (IBAction) logoutFromService; - (IBAction) retrieveUsersPersonalStream:(id)sender; @end Thursday, June 13, 13
  136. 136. - (void) loginToService { WebServiceLoginCommand *command = [WebServiceLoginCommand commandWithService:self]; command.tokenStorage = self.tokenStorage; command.username = [self.delegate username]; command.password = [self.delegate password]; [command send]; } Thursday, June 13, 13
  137. 137. - (NSString *)username; { return [self textValueForCellAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; } - (NSString *)password; { return [[self textValueForCellAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]] lowercaseString]; } - (IBAction) login:(id)sender; { if ([[self username] length] && [[self password] length]) { self.messageLabel.text = @""; [[UIApplication sharedApplication] performActionInResponderChain:@selector(resignFirstResponder) from:self]; [SVProgressHUD showWithStatus:@"Logging in..." maskType:SVProgressHUDMaskTypeBlack]; } } Thursday, June 13, 13
  138. 138. - (void) sendCommand:(WebServiceCommand *)command; { BOOL commandVerified = [self verifyCommand:command]; if (!commandVerified) return; if ([self.httpClient networkReachabilityStatus] == AFNetworkReachabilityStatusNotReachable) { [self.delegate displayMessage:@"No Internet Connection"]; DDLogInfo(@"Not connected to a network"); } else { AFHTTPRequestOperation *operation = [command createRequestOperation]; [self.httpClient enqueueHTTPRequestOperation:operation]; DDLogInfo(@"Sent Command: %@", command); } } Thursday, June 13, 13
  139. 139. - (void) sendCommand:(WebServiceCommand *)command; { BOOL commandVerified = [self verifyCommand:command]; if (!commandVerified) return; if ([self.httpClient networkReachabilityStatus] == AFNetworkReachabilityStatusNotReachable) { [self.delegate displayMessage:@"No Internet Connection"]; DDLogInfo(@"Not connected to a network"); } else { AFHTTPRequestOperation *operation = [command createRequestOperation]; [self.httpClient enqueueHTTPRequestOperation:operation]; DDLogInfo(@"Sent Command: %@", command); } } Thursday, June 13, 13
  140. 140. - (void) sendCommand:(WebServiceCommand *)command; { BOOL commandVerified = [self verifyCommand:command]; if (!commandVerified) return; if ([self.httpClient networkReachabilityStatus] == AFNetworkReachabilityStatusNotReachable) { [self.delegate displayMessage:@"No Internet Connection"]; DDLogInfo(@"Not connected to a network"); } else { AFHTTPRequestOperation *operation = [command createRequestOperation]; [self.httpClient enqueueHTTPRequestOperation:operation]; DDLogInfo(@"Sent Command: %@", command); } } Thursday, June 13, 13
  141. 141. [self.delegate displayMessage:@"No Internet Connection"]; DDLogInfo(@"Not connected to a network"); Thursday, June 13, 13
  142. 142. AFHTTPRequestOperation *operation = [command createRequestOperation]; [self.httpClient enqueueHTTPRequestOperation:operation]; DDLogInfo(@"Sent Command: %@", command); Thursday, June 13, 13
  143. 143. ommand Object WebService Object Our App Actual Service Thursday, June 13, 13
  144. 144. WebService Object Our App HTTP Requ Actual Service Thursday, June 13, 13
  145. 145. HTTP Respons WebService Object Our App Actual Service Thursday, June 13, 13
  146. 146. WebService Object ble ObjectOur App Actual Service Thursday, June 13, 13
  147. 147. Usable Object Needs to be more clear Thursday, June 13, 13
  148. 148. Needs to be more clear Usable Object Thursday, June 13, 13
  149. 149. Thursday, June 13, 13
  150. 150. NSFetchedResultsController Thursday, June 13, 13
  151. 151. - (void) loadUserStream; { self.results = [StreamEvent MR_fetchAllSortedBy:StreamEvent.createdDate ascending:YES withPredicate:[self streamFilter] groupBy:nil delegate:self inContext:self.context]; } Thursday, June 13, 13
  152. 152. - (void) loadUserStream; { self.results = [StreamEvent MR_fetchAllSortedBy:StreamEvent.createdDate ascending:YES withPredicate:[self streamFilter] groupBy:nil delegate:self inContext:self.context]; } Thursday, June 13, 13
  153. 153. NSFetchedResultsControllerDelegate Thursday, June 13, 13
  154. 154. Delegation Thursday, June 13, 13
  155. 155. AbstractTemplate ConcreteTemplate Thursday, June 13, 13
  156. 156. AbstractTemplate ConcreteTemplate Thursday, June 13, 13
  157. 157. AbstractTemplate ConcreteTemplate Thursday, June 13, 13
  158. 158. AbstractTemplate ConcreteTemplate Thursday, June 13, 13
  159. 159. - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)theIndexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath - (void)controllerWillChangeContent:(NSFetchedResultsController *)controller - (void)controllerDidChangeContent:(NSFetchedResultsController *)controller Thursday, June 13, 13
  160. 160. switch(type) { case NSFetchedResultsChangeInsert: [tableView insertRowsAtIndexPaths:@[theIndexPath] withRowAnimation:UITableViewRowAnimationNone]; break; case NSFetchedResultsChangeDelete: [self verifyProductPredicate:anObject]; [tableView deleteRowsAtIndexPaths:@[theIndexPath] withRowAnimation:UITableViewRowAnimationFade]; break; case NSFetchedResultsChangeUpdate: { id object = [self.results objectAtIndexPath:theIndexPath]; [self configureCell:(id)[tableView cellForRowAtIndexPath:theIndexPath] forObject:object]; } break; case NSFetchedResultsChangeMove: [tableView deleteRowsAtIndexPaths:@[theIndexPath] withRowAnimation:UITableViewRowAnimationFade]; [tableView insertRowsAtIndexPaths:@[theIndexPath] withRowAnimation:UITableViewRowAnimationFade]; break; } Thursday, June 13, 13
  161. 161. Observer Last steps from controller to view with observer pattern Thursday, June 13, 13
  162. 162. Model Controller View Thursday, June 13, 13
  163. 163. Composite Command Mediator Strategy Observer Thursday, June 13, 13
  164. 164. Model ViewController View Thursday, June 13, 13
  165. 165. Model ViewController View Thursday, June 13, 13
  166. 166. Model ViewController View Thursday, June 13, 13
  167. 167. Model ViewController View Thursday, June 13, 13
  168. 168. Model ViewController View Thursday, June 13, 13
  169. 169. Touch Interface View ViewController App.net App.net AppDelegate CoreData Thursday, June 13, 13
  170. 170. Touch Interface View ViewController App.net App.net AppDelegate CoreData Thursday, June 13, 13
  171. 171. Touch Interface View ViewController App.net App.net AppDelegate CoreData Thursday, June 13, 13
  172. 172. Touch Interface View ViewController App.net App.net AppDelegate CoreData Thursday, June 13, 13
  173. 173. Touch Interface View ViewController App.net App.net AppDelegate CoreData Thursday, June 13, 13
  174. 174. Touch Interface View ViewController App.net App.net AppDelegate CoreData Thursday, June 13, 13
  175. 175. Touch Interface View ViewController App.net App.net AppDelegate CoreData Thursday, June 13, 13
  176. 176. Touch Interface View ViewController App.net App.net AppDelegate CoreData Thursday, June 13, 13
  177. 177. Touch Interface View ViewController App.net App.net AppDelegate CoreData Thursday, June 13, 13
  178. 178. Touch Interface View ViewController App.net App.net AppDelegate CoreData Thursday, June 13, 13
  179. 179. Touch Interface View ViewController App.net App.net AppDelegate CoreData Thursday, June 13, 13
  180. 180. Touch Interface View ViewController App.net App.net AppDelegate CoreData Thursday, June 13, 13
  181. 181. Pattern Abuse Thursday, June 13, 13
  182. 182. Factory Thursday, June 13, 13
  183. 183. Abstract Factories Thursday, June 13, 13
  184. 184. Two-Stage Creation Thursday, June 13, 13
  185. 185. [[MyClass alloc] init] Thursday, June 13, 13
  186. 186. NSClassFromString Thursday, June 13, 13
  187. 187. [NSClassFromString(@”MyClass”) alloc] init] Thursday, June 13, 13
  188. 188. Singletons More explanation in slides Thursday, June 13, 13
  189. 189. Singletons More explanation in slides Thursday, June 13, 13
  190. 190. More explanation in slides Thursday, June 13, 13
  191. 191. Thursday, June 13, 13
  192. 192. Thursday, June 13, 13
  193. 193. Singleton ViewController AppDelegate Thursday, June 13, 13
  194. 194. Singleton ViewController AppDelegate Thursday, June 13, 13
  195. 195. Singleton ViewController AppDelegate Model ObjectNetwork Web Service Thursday, June 13, 13
  196. 196. Singleton ViewController AppDelegate Model ObjectNetwork Web Service Thursday, June 13, 13
  197. 197. Singleton ViewController AppDelegate Model ObjectNetwork Web Service Thursday, June 13, 13
  198. 198. Singleton ViewController AppDelegate Model ObjectNetwork Web ServiceWeb ServiceWeb Service ViewControllerViewControllerViewControllerViewControllerViewController Model ObjectModel ObjectModel ObjectModel ObjectModel ObjectModel Object Thursday, June 13, 13
  199. 199. Singleton Thursday, June 13, 13
  200. 200. Singleton Thursday, June 13, 13
  201. 201. AppDelegate Thursday, June 13, 13
  202. 202. Singleton Manager AppDelegate Thursday, June 13, 13
  203. 203. Singleton Manager AppDelegate Singleton Singleton Singleton Thursday, June 13, 13
  204. 204. Singleton ManagerAppDelegate -instanceForClass:[Singleton class] Thursday, June 13, 13
  205. 205. Singleton ManagerAppDelegate Thursday, June 13, 13
  206. 206. Singleton ManagerAppDelegate -destroyInstanceForClass:[Singleton class] Thursday, June 13, 13
  207. 207. Singleton ManagerAppDelegate Thursday, June 13, 13
  208. 208. SingletonSingleton ManagerAppDelegate ViewController Thursday, June 13, 13
  209. 209. Singleton Singleton ManagerAppDelegate ViewController Thursday, June 13, 13
  210. 210. ServiceLocator Thursday, June 13, 13
  211. 211. Classes are objects too... Thursday, June 13, 13
  212. 212. @property Class dateCreator; Thursday, June 13, 13
  213. 213. [self.dateCreator date]; Thursday, June 13, 13
  214. 214. Thursday, June 13, 13
  215. 215. Thursday, June 13, 13
  216. 216. Thursday, June 13, 13
  217. 217. Thursday, June 13, 13
  218. 218. Thursday, June 13, 13
  219. 219. Thursday, June 13, 13
  220. 220. Thursday, June 13, 13
  221. 221. It was important, his father said, to craft the backs of cabinets and fences properly, even though they were hidden. Steve Jobs by Walter Isaacson Thursday, June 13, 13
  222. 222. “He loved doing things right. He even cared about the look of the parts you couldn’t see.” - Steve Jobs Thursday, June 13, 13
  223. 223. saul@magicalpanda.com Thursday, June 13, 13

×