Search code examples
iosobjective-ctyphoon

How do I access the assembly that is plist activated?


I am transitioning a project to use plist integration for Typhoon. I can see that the assemblies that I added to the TyphoonInitialAssemblies key are being activated, but after I don't know how to access the activated assembly.


Solution

  • You can access the assemblies by injecting it/them. You can define a special case definition for the App Delegate, as shown in the Typhoon example application:

    - (PFAppDelegate *)appDelegate
    {
    return [TyphoonDefinition withClass:[PFAppDelegate class]     
        configuration:^(TyphoonDefinition *definition)
        {
            //Inject the assembly
            [definition injectProperty:@selector(assembly)
                with:self];
    
            //Inject other properties
            [definition injectProperty:@selector(window)
                with:[self mainWindow]];
            [definition injectProperty:@selector(cityDao) 
                with:[_coreComponents cityDao]];            
        }];
    }
    

    . . or you can inject the assembly into any other Typhoon created component as well. This is useful from proceeding from one object graph to another with the factory pattern.

    • Note that for the App Delegate (or other objects created outside of Typhoon) that property and method injection will work fine, but initializer injection is of course not supported. Also you can't down-scope an object, that is, a singleton created outside of Typhoon declared as a prototype, will remain a singleton.
    • Also note that, if you wish, you can back your assemblies with a protocol, so that its not necessary to couple your classes directly to Typhoon.

    The assembly bootstrapped via plist integration is also the one that is bound to your initial/main storyboard, so any auto-injection properties defined on your storyboard created view controllers will be fulfilled. This includes an assembly type property, eg:

    @property(nonatomic, strong) InjectedClass(MyAssembly) assembly; 
    

    The documentation for this feature is here.