$30 off During Our Annual Pro Sale. View Details »

Unburdened ViewControllers by Jay Thrash

Unburdened ViewControllers by Jay Thrash

Jay discusses an alternative to MVC that can help in creating less cluttered view controllers from CocoaHeads August in Raleigh

Triangle Cocoa

August 23, 2012
Tweet

More Decks by Triangle Cocoa

Other Decks in Programming

Transcript

  1. Unburdened
    ViewControllers
    Triangle CocoaHeads - Aug 2012
    Jay Thrash :: [email protected] :: @jaythrash

    View Slide

  2. In the Beginning..
    View
    Controller
    View
    Model
    Model View

    View Slide

  3. Quickly
    becomes...

    View Slide

  4. Quickly
    becomes...
    SOAP
    REST
    Core
    Data

    View Slide

  5. Beginning of the End
    ViewController
    View
    Model
    Model View
    SOAP
    REST
    Core
    Data

    View Slide

  6. View Slide

  7. Open a Store

    View Slide

  8. iOS Programming
    Big Nerd Ranch Guide

    View Slide

  9. Store-Controllers
    CMMotionManager CLLocationManager

    View Slide

  10. Model
    View
    Controller
    Store

    View Slide

  11. MVC(S)
    Controller
    Model
    External
    Data
    Store
    View
    Controller
    Model
    View

    View Slide

  12. Store Interface
    #import
    @class CHItem;
    @interface CHItemStore : NSObject
    {
    NSMutableArray *items;
    }
    // Access the singleton Store
    + (CHItemStore *)store;
    // Access Store contents
    - (NSArray *)allItems;
    - (void)addItem:(CHItem *)item;
    - (void)removeItem:(CHItem *)item;
    // Persist Store contents
    - (BOOL)save:(NSError *)err;
    @end

    View Slide

  13. Store Responsibilities
    • Model Objects from Data Sources
    • Handles Loading & Saving of Model
    Objects
    • Encapsulates Caching and Lazy
    Fetching

    View Slide

  14. Before & After
    Store Controller
    Fetches Models Controls Flow
    Persists Models
    Get, Update, Insert
    using Store
    Encapsulates Saving Requests Saving
    Caches Data
    Not concerned with
    data caching

    View Slide

  15. Extra Credit
    • Asynchronous Data Requests
    • Memory Management
    • Caching
    • Lazy Loading

    View Slide

  16. Change Your
    View

    View Slide

  17. Third Wheel
    Controller
    View
    Model View
    External
    Data
    Store
    Model

    View Slide

  18. Frictionless
    Controller
    View
    Model
    View
    External
    Data
    Store
    Model

    View Slide

  19. Benefits
    • Reusable Views - Just add a Model
    • ViewController as Conductor
    • Interface with Store
    • Handle User’s Input

    View Slide

  20. Name Author URL
    iOS Programming Joe Conway and
    Aaron Hillegass
    http://www.bignerdranch.com
    Ubuntu Font
    Family
    Canonical, Ltd. http://font.ubuntu.com/
    Unburdened ViewControllers
    Jay Thrash :: [email protected] :: @jaythrash
    Resources & Attributions

    View Slide