Slide 39
Slide 39 text
#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: ...");
}
};
}