Skip to content

TyphoonLoadedView

Igor Vasilenko edited this page Jul 13, 2016 · 4 revisions

Imagine case when we have an UITableView with custom cell's with some dependencies like Presenter, Animator, Router, ViewModel, etc. How you will be passing this dependencies to your custom cell?

For solving this problem was implemented TyphoonLoadedView.

TyphoonLoadedView works really simple.

It's just override - (id)awakeAfterUsingCoder:(NSCoder *)aDecoder, search view definition for typhoon key from [TyphoonComponentFactory factoryForResolvingUI] and returns replacement view from definition.

Getting started

@interface CustomTableViewCell : UITableViewCell

@property (strong, nonatomic) TableViewCellViewModel *viewModel;

@end

Notice : For TyphoonLoadedView we need to set Restoration ID, it's will be your typhoon key for definition.

In the last step you just need to add definitions in your some assembly:

- (UITableViewCell *)customTableViewCell
{
    return [TyphoonDefinition withClass:[CustomTableViewCell class] configuration:^(TyphoonDefinition *definition) {
        [definition injectProperty:@selector(viewModel) with:[self tableViewCellViewModel]];
    }];
}

- (TableViewCellViewModel *)tableViewCellViewModel
{
    return [TyphoonDefinition withClass:[TableViewCellViewModel class] configuration:^(TyphoonDefinition *definition) {
        [definition injectProperty:@selector(titleLabelString) with:@"Test"];
    }];
}