Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injected property is nil #539

Open
pinchukvd opened this issue Nov 30, 2016 · 4 comments
Open

Injected property is nil #539

pinchukvd opened this issue Nov 30, 2016 · 4 comments
Labels

Comments

@pinchukvd
Copy link

Hi
I'm getting a nil property after injection. Here is my code:

@implementation MainVCAssembly

-(MainVCViewModel*)viewModel
{
    return [TyphoonDefinition withClass:[MainVCViewModel class] configuration:^(TyphoonDefinition *definition) {
        [definition injectProperty:@selector(bankDataService) with:[self bankDataService]];
    }];
}

-(id<UserDataService>)bankDataService
{
    return [self.servicesAssembly userDataService];
}

UserDataServiceImplementation is injected successfuly.
But when injecting an operationsAssembly in userDataService

@implementation ServicesAssemblyImplementation

-(id<UserDataService>)userDataService
{
    return [TyphoonDefinition withClass:[UserDataServiceImplementation class] configuration:^(TyphoonDefinition *definition) {
           [definition injectProperty:@selector(operationsAssembly) with:[self operationsAssembly]];
    }];
}

-(id<OperationsAssembly>)operationsAssembly
{
    return [TyphoonDefinition withClass:[OperationsAssemblyImplementation class] configuration:^(TyphoonDefinition *definition) {
    }];
}

i'm getting a nil in setter

@implementation UserDataServiceImplementation

-(void)setOperationsAssembly:(id<OperationsAssembly>)operationsAssembly
{
    NSLog(@"set operationsAssembly in UserDataServiceImplementation");
    if(!operationsAssembly)
    {
        NSLog(@"operationsAssembly is nil");
    }
}
@alexgarbarev
Copy link
Contributor

alexgarbarev commented Nov 30, 2016

Your code looks correct from first sight.
Try something of this:

  1. Try to not override operationsAssembly setter.
  2. Make sure that operationsAssembly property exists (not only setter/getter)
  3. try to inject setOperationsAssembly via methodInjection instead
  4. try latest version with
  pod 'Typhoon', :git => 'https://github.com/appsquickly/Typhoon.git', :branch => 'v4'

@pinchukvd
Copy link
Author

Tried first three and still getting nil.
With v4 got problems with manual activation.
Getting TyphoonAssemblyAccessor instead of MainVCAssembly instance

MainVCAssembly *assembly=(MainVCAssembly*)[[self.controllersAssembly activated] mainViewControllerAssembly];

threfore it's unrecognized selector sent to instance

@alexgarbarev
Copy link
Contributor

alexgarbarev commented Dec 1, 2016

Getting TyphoonAssemblyAccessor instead of MainVCAssembly instance

That's ok

threfore it's unrecognized selector sent to instance

Because you should pass collaborating assemblies inside activation. See activateWithCollaboratingAssemblies for reference

@alexgarbarev
Copy link
Contributor

Ah, you are right regarding "threfore it's unrecognized selector sent to instance". Latest pull request broke that branch.

@etolstoy etolstoy added the bug label Feb 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants