Search code examples
iosobjective-cinjecttyphoon

Typhoon inject property


I have problems with injecting BOOL property.

I've tried next:

- (id)emotionControllerWithItem:(MDDiaryItem *)item firstController:(BOOL)isFirst
{
    return [TyphoonDefinition withClass:[MDEmotionViewController class]
                          configuration: ^(TyphoonDefinition *definition) {
                [definition useInitializer:@selector(initWithAnalytics:) parameters: ^(TyphoonMethod *initializer) {
                    [initializer injectParameterWith:[_services analytics]];
                }];
                [definition injectProperty:@selector(setItem:) with:item];
                [definition injectProperty:@selector(setFirstController:) with:[NSNumber numberWithBool:isFirst]];
            }];
}

But it crashes in runtime with EXC_BAD_ACCESS. Actually it is nothing about BOOL property but injection properties with values itself. It looks like my assumption about Typhoon usage is wrong.


Solution

  • Runtime arguments must be always an object - not primitive type!

    The correct assembly is here:

    - (id)emotionControllerWithItem:(MDDiaryItem *)item firstController:(NSNumber *)isFirst
    {
        return [TyphoonDefinition withClass:[MDEmotionViewController class]
                              configuration: ^(TyphoonDefinition *definition) {
                    [definition useInitializer:@selector(initWithAnalytics:) parameters: ^(TyphoonMethod *initializer) {
                        [initializer injectParameterWith:[_services analytics]];
                    }];
                    [definition injectProperty:@selector(setItem:) with:item];
                    [definition injectProperty:@selector(setFirstController:) with:isFirst];
                }];
    }
    

    where firstController property can has BOOL, but when calling assmebly interface, you have to use NSNumber wrapper:

    [assembly emotionControllerWithItem:item firstController:@YES];