Skip to content

MVVMC table view tutorial

Marko Hlebar edited this page Mar 22, 2015 · 2 revisions

This tutorial should teach you the basics of working with BIND as well as MVVMC architecture. The tutorial assumes you know the basics of programming with Cocoa and Xcode, but beginners should find it easy to follow as well.

We will start off by creating a simple table view which will load some data from a JSON file, and then present each person's name alphabetically in the table view.

First, create a new project in Xcode, and install BIND pod. If you are unsure how to do that, head off to http://www.cocoapods.org/ and read a tutorial on installing and managing pods.

Next, head off to https://www.mockaroo.com/ and create a .json file that you will use as your data. The service should spit out a MOCK_DATA.json. Import that file into your project.

At this point, we can start writing some code :)
We will start by creating a data controller. A data controller is a class that should supply the views with their viewModels and basically does a conversion of business logic to presentation logic. Create a subclass of NSObject and call it PersonsDataController. Also you will have to import BIND.h and implement the BNDDataController protocol like the following listing.

PersonsDataController.h

#import <Foundation/Foundation.h>
#import <BIND/BIND.h>

@interface PersonsDataController : NSObject <BNDDataController>
@end

PersonsDataController.m

#import "PersonsDataController.h"
@implementation PersonsDataController

- (void)updateWithContext:(id)context viewModelsHandler:(BNDViewModelsBlock)viewModelsHandler {

}

@end 

Observe the - (void)updateWithContext:viewModelsHandler: method. This should be the only public interface for any data controller. The operations performed here should be loading a model from an external service, and then transforming that model to a viewModel suitable for view presentation. We will return later to implement this method.

TBC...

Clone this wiki locally