SlideShare a Scribd company logo
MVC na iOS


Tomáš Jukin
@Inza
Únor 2013 - iOS
Únor 2013 - iOS


www.srazy.info/for-mobile
@forMobileCZ #forMobileCZ

   www.for-mobile.cz
www.juicymo.cz
imagination idea innovation




www.iknow.eu/cvut/
www.inovacentrum.cvut.cz/inovajet
www.facebook.com/dtvpraha7
Novinky


Prostor pro vás ;)
MVC na iOS


Tomáš Jukin
@Inza
MVC na iOS
MVC = Model-View-Controller

ale v iOS...

MVC
= Massive ViewController
MVC na iOS
nejčastěji v praxi:

MVC = Asynchronní načítání dat
z internetu do UITableView
MVC na iOS
nejčastěji v praxi:

MVC = Asynchronní načítání
dat z internetu do UITableView
MVC na iOS
nejčastěji v praxi:

MVC = Asynchronní načítání
dat z internetu do UITableView
pomocí bloků
Byla jednou jedna tabulka...




load data
Byla jednou jedna tabulka...


                               array




load data
Byla jednou jedna tabulka...


                               array




load data
Byla jednou jedna tabulka...


                               array




load data    anim. update
Byla jednou jedna tabulka...   cache




                               array




load data    anim. update
Byla jednou jedna tabulka...                  cache




                                              array




                            při update mažu
                                 cache...

load data    anim. update
Byla jednou jedna tabulka...                   cache




                                               array




                controller
                  switch
                             při update mažu
                                  cache...

load data    anim. update
Byla jednou jedna tabulka...
                                      cache




                              array




  controller
    switch



load data      anim. update
Byla jednou jedna tabulka...
                                      cache




                              array




  controller
                                              na pozadí
    switch



load data      anim. update
Byla jednou jedna tabulka...




                            update    load
                            cache    cache


load data    anim. update
Byla jednou jedna tabulka...
            V                  C   M




load data       anim. update
Byla jednou jedna tabulka...
            V                  C   M
                                       User
                                       Item
                                         ...




load data       anim. update
A co API?
A co API?




  programátor
A co API?
A co API?




       UITableView
         iOS API
A co API?
A co API?




        ???
A co API?

 c blocks

             +



            MVC
Jak na MC?                    owns
                          load data

             controller




    view                     model
Jak na MC?                             owns
                                      load data
         app                            refresh
       delegate
                         controller




                  view                   model




vylez z metra
Jak na MC?                           owns
                                 load data
    app
  delegate
                    controller




             view                    model




                                 na pozadí
Jak na MC?                        owns
                                 load data
       iOS                             kill
                    controller




             view                   model




zpět
Jak na MC?                        owns
                                 load data
       iOS                             kill
                    controller




             view                   model



                                              ???
zpět
Jak na MC?             model
                         manager
                                          owns
                                      load data
         app
       delegate
                                            kill
                         controller




                          proxy
                  view                   model
                          model




zpět
#pragma mark - Setup Models
-   (void)setupModelsConfiguration {
	    DEFINE_BLOCK_SELF;
	    self.modelConfigurationRecipe = ^(JMTableViewModel *model, NSString *modelIdentifier) {
	    	     NSString *defaultModelIdentifier = [blockSelf modelIdentifier];
	
	    	    if ([modelIdentifier isEqualToString:defaultModelIdentifier]) {
	    	    	   #pragma mark - Cell Recipe
	    	    	   // Cell Configuration (how to pass data from cellModel to cell)
	    	    	   model.cellConfigurationRecipe = ^(UITableViewCell *c, JMTableViewCellModel *cM, NSIndexPath *iP) {
	    	    	   	    // ...
	    	    	   };
	    	    	
	    	    	   #pragma mark - Preload recipe
	    	    	   model.preloadRecipe = ^(NSMutableArray *cache) { /* ... */ };
	    	    	
	    	    	   #pragma mark - Load recipe
	    	    	   model.loadRecipe = ^(NSMutableArray *cache, NSArray *loadedObjects) { /* ... */ };
	    	    	
	    	    	   if ([model isKindOfClass:[JMRESTTableViewModel class]]) {
	    	    	   	    JMRESTTableViewModel *restModel = ((JMRESTTableViewModel *)model);
	    	    	   	
	    	    	   	    __block JMRESTTableViewModel *blockRestModel = restModel;
	    	    	   	    #pragma mark - Parse recipe
	    	    	   	    restModel.parseRecipe = ^(NSMutableArray *cache, id parsedJSONDataObject) {
	    	    	   	    	   // ...
	    	    	   	    	   	
	    	    	   	    	   // ...and pass it to loadRecipe block
	    	    	   	    	   blockRestModel.loadRecipe(cache, section);
	    	    	   	    };
	    	    	   }
	    	    }
	    	    else {
	    	    	   NSLog(@"Error: ...");
	    	    }
	    };
}
Next
Next ?
Onscreen vs. Offscreen rendering v iOS

KVC, KVO a Cocoa Bindings

Document Oriented Programing v Cocoa

Advanced Cora Data

More Related Content

More from Tomáš Jukin

Arduino Neural Networks
Arduino Neural NetworksArduino Neural Networks
Arduino Neural Networks
Tomáš Jukin
 
Multi-Agent Systems on Arduino & iOS
Multi-Agent Systems on Arduino & iOSMulti-Agent Systems on Arduino & iOS
Multi-Agent Systems on Arduino & iOS
Tomáš Jukin
 
CoreData - there is an ORM you can like!
CoreData - there is an ORM you can like!CoreData - there is an ORM you can like!
CoreData - there is an ORM you can like!
Tomáš Jukin
 
Few tips for great presentations
Few tips for great presentationsFew tips for great presentations
Few tips for great presentations
Tomáš Jukin
 
Bezpečnost platformy iOS
Bezpečnost platformy iOSBezpečnost platformy iOS
Bezpečnost platformy iOS
Tomáš Jukin
 
ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013
ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013
ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013
Tomáš Jukin
 
iOS6 & CocoaPods - For-Mobile 9/2012
iOS6 & CocoaPods - For-Mobile 9/2012iOS6 & CocoaPods - For-Mobile 9/2012
iOS6 & CocoaPods - For-Mobile 9/2012
Tomáš Jukin
 
Make the code work for you with #git
Make the code work for you with #gitMake the code work for you with #git
Make the code work for you with #git
Tomáš Jukin
 
Tools beyond ruby on rails
Tools beyond ruby on railsTools beyond ruby on rails
Tools beyond ruby on rails
Tomáš Jukin
 

More from Tomáš Jukin (9)

Arduino Neural Networks
Arduino Neural NetworksArduino Neural Networks
Arduino Neural Networks
 
Multi-Agent Systems on Arduino & iOS
Multi-Agent Systems on Arduino & iOSMulti-Agent Systems on Arduino & iOS
Multi-Agent Systems on Arduino & iOS
 
CoreData - there is an ORM you can like!
CoreData - there is an ORM you can like!CoreData - there is an ORM you can like!
CoreData - there is an ORM you can like!
 
Few tips for great presentations
Few tips for great presentationsFew tips for great presentations
Few tips for great presentations
 
Bezpečnost platformy iOS
Bezpečnost platformy iOSBezpečnost platformy iOS
Bezpečnost platformy iOS
 
ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013
ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013
ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013
 
iOS6 & CocoaPods - For-Mobile 9/2012
iOS6 & CocoaPods - For-Mobile 9/2012iOS6 & CocoaPods - For-Mobile 9/2012
iOS6 & CocoaPods - For-Mobile 9/2012
 
Make the code work for you with #git
Make the code work for you with #gitMake the code work for you with #git
Make the code work for you with #git
 
Tools beyond ruby on rails
Tools beyond ruby on railsTools beyond ruby on rails
Tools beyond ruby on rails
 

MVC na iOS - For-Mobile 2/2013

  • 1. MVC na iOS Tomáš Jukin @Inza
  • 3. Únor 2013 - iOS www.srazy.info/for-mobile @forMobileCZ #forMobileCZ www.for-mobile.cz
  • 9. MVC na iOS Tomáš Jukin @Inza
  • 10. MVC na iOS MVC = Model-View-Controller ale v iOS... MVC = Massive ViewController
  • 11. MVC na iOS nejčastěji v praxi: MVC = Asynchronní načítání dat z internetu do UITableView
  • 12. MVC na iOS nejčastěji v praxi: MVC = Asynchronní načítání dat z internetu do UITableView
  • 13. MVC na iOS nejčastěji v praxi: MVC = Asynchronní načítání dat z internetu do UITableView pomocí bloků
  • 14. Byla jednou jedna tabulka... load data
  • 15. Byla jednou jedna tabulka... array load data
  • 16. Byla jednou jedna tabulka... array load data
  • 17. Byla jednou jedna tabulka... array load data anim. update
  • 18. Byla jednou jedna tabulka... cache array load data anim. update
  • 19. Byla jednou jedna tabulka... cache array při update mažu cache... load data anim. update
  • 20. Byla jednou jedna tabulka... cache array controller switch při update mažu cache... load data anim. update
  • 21. Byla jednou jedna tabulka... cache array controller switch load data anim. update
  • 22. Byla jednou jedna tabulka... cache array controller na pozadí switch load data anim. update
  • 23. Byla jednou jedna tabulka... update load cache cache load data anim. update
  • 24. Byla jednou jedna tabulka... V C M load data anim. update
  • 25. Byla jednou jedna tabulka... V C M User Item ... load data anim. update
  • 27. A co API? programátor
  • 29. A co API? UITableView iOS API
  • 31. A co API? ???
  • 32. A co API? c blocks + MVC
  • 33. Jak na MC? owns load data controller view model
  • 34. Jak na MC? owns load data app refresh delegate controller view model vylez z metra
  • 35. Jak na MC? owns load data app delegate controller view model na pozadí
  • 36. Jak na MC? owns load data iOS kill controller view model zpět
  • 37. Jak na MC? owns load data iOS kill controller view model ??? zpět
  • 38. Jak na MC? model manager owns load data app delegate kill controller proxy view model model zpět
  • 39. #pragma mark - Setup Models - (void)setupModelsConfiguration { DEFINE_BLOCK_SELF; self.modelConfigurationRecipe = ^(JMTableViewModel *model, NSString *modelIdentifier) { NSString *defaultModelIdentifier = [blockSelf modelIdentifier]; if ([modelIdentifier isEqualToString:defaultModelIdentifier]) { #pragma mark - Cell Recipe // Cell Configuration (how to pass data from cellModel to cell) model.cellConfigurationRecipe = ^(UITableViewCell *c, JMTableViewCellModel *cM, NSIndexPath *iP) { // ... }; #pragma mark - Preload recipe model.preloadRecipe = ^(NSMutableArray *cache) { /* ... */ }; #pragma mark - Load recipe model.loadRecipe = ^(NSMutableArray *cache, NSArray *loadedObjects) { /* ... */ }; if ([model isKindOfClass:[JMRESTTableViewModel class]]) { JMRESTTableViewModel *restModel = ((JMRESTTableViewModel *)model); __block JMRESTTableViewModel *blockRestModel = restModel; #pragma mark - Parse recipe restModel.parseRecipe = ^(NSMutableArray *cache, id parsedJSONDataObject) { // ... // ...and pass it to loadRecipe block blockRestModel.loadRecipe(cache, section); }; } } else { NSLog(@"Error: ..."); } }; }
  • 40. Next
  • 41. Next ? Onscreen vs. Offscreen rendering v iOS KVC, KVO a Cocoa Bindings Document Oriented Programing v Cocoa Advanced Cora Data