Skip to content

Storyboards

Jasper Blues edited this page Mar 1, 2019 · 11 revisions

Typhoon ensures that all storyboards used in the application are instances of TyphoonStoryboard under the hood. You don't have to worry about it - just work with UIStoryboard as you would normally do, with the added benefit that dependencies will be injected according to the definitions in your TyphoonAssembly class(es).

This approach also works with the new iOS feature - Storyboard References.

The TyphoonComponentFactory will be retained by the storyboard, and so persists throughout the life-cycle of your application.

By default Typhoon will inject by matching the type of the UIViewController to a component in the assembly. Optionally, you can specify which definition should be used for each viewController using the 'typhoonKey' runtime attribute. Example:

TyphoonStoryBoard

Creating a new Storyboard Programmatically

If you wish to create additional storyboards programmatically, as some people do, for example, do provide one storyboard per use-case:

On the fly:

UIStoryboard *board = [UIStoryboard storyboardWithName:@"AStoryBoardName" 
    bundle:[NSBundle mainBundle]];

In an assembly:

- (UIStoryboard *)storyboard
{
    return [TyphoonDefinition withClass:[UIStoryboard class] configuration:^(TyphoonDefinition *definition) {
        [definition useInitializer:@selector(storyboardWithName:factory:bundle:)
            parameters:^(TyphoonMethod *initializer) {
                [initializer injectParameterWith:@"StoryboardName"];
                [initializer injectParameterWith:[NSBundle mainBundle]];
            }];
    }];
}

Blacklisting Storyboards

If you don't want a specific storyboard to be powered by Typhoon - use a plist integration. Add a special key TyphoonCleanStoryboards in your Info.plist file and list all the storyboards that don't need the activation.



See also: Storyboards work well in conjunction with Autowiring