Search code examples
objective-ctyphoon

Instantiate a view controller from UIStoryBoard after using TyphoonAssemblyActivator


After using the new API with the TyphoonAssemblyActivator interface, I would like to instantiate a UIViewController located within a UIStoryBoard, but it misses the factory instance.

How should I do this ?


Solution

  • TyphoonAssemblyActivator is useful for bootstrapping Typhoon in a library or somewhere within a legacy application. For a fully-Typhoon powered application its better to use plist integration.

    Just add the name of your TyphoonAssembly classes in your app's plist file, and optionally inject your AppDelegate class. Having done this:

    • Instances of Storyboard will be TyphoonStoryboard, behave just like regular storyboards with the added benefit that dependencies are injected. You can define a definition for injections in an assembly or use the auto-injection macros.
    • Bootstrapping Typhoon this way also means that UIStateRestoration in Storyboards works as expected.

    If for some reason you did want to create a TyphoonStoryboard manually you could create a definition for one in the assembly as:

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