Skip to content

AppDelegate Integration

Egor Tolstoy edited this page Aug 28, 2015 · 1 revision

##What is automatic instantiation?

Automatic instantiation of initial set of TyphoonAssembly classes is done via implementing a specific AppDelegate methods.

##Why do I ever need this?

Sometimes, especially in a large app, especially with the VIPER architecture or with a large number of abstract factories, there are a lot of TyphoonAssembly subclasses, and all of them need to be activated on startup.

In such case Info.plist looks rather messy - too many fields without any grouping by layers.

##How can I do it?

Just implement one of two methods in the AppDelegate class:

// this method should return a TyphoonBlockComponentFactory with already activated TyphoonAssembly subclasses
- (id)initialFactory;

// this method should return an array of TyphoonAssembly subclasses, which should be activated on startup
- (NSArray *)initialAssemblies;

Here is an example:

- (NSArray *)initialAssemblies
{
    return @[
             [MiddleAgesAssembly class],
             [CollaboratingMiddleAgesAssembly class]
             ];
}

Please note, that if you provide both methods, - (NSArray *)initialAssemblies will be used.

##What can I do with it?

You are not forced to provide the assembly classes as a hardcoded array - feel free to implement any kind of runtime search of TyphoonAssembly (maybe via some naming convention or using a specific protocol).

P.S. This approaches also work with UIStateRestoration in Storyboards, so are an alternative to plist integration in that regard.