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

TyphoonFactoryProvider: By-convention approach fails with 'propertyNotFound' #175

Closed
jasperblues opened this issue Feb 12, 2014 · 4 comments

Comments

@jasperblues
Copy link
Member

Steps to reproduce:

Create a factory as follows:

@protocol VBRequestRVIControllerFactory

@property(nonatomic, strong, readonly) VBRequestRVIView* rviView;

- (VBRequestRVIViewController*)controllerWithDelegate:(id <VBRequestRVIControllerDelegate>)delegate;

@end

For a controller:

@interface VBRequestRVIViewController : UIViewController

@property(nonatomic, strong) VBRequestRVIView* rviView;
@property(nonatomic, weak, readonly) id <VBRequestRVIControllerDelegate> delegate;

- (instancetype)initWithRviView:(VBRequestRVIView*)rviView delegate:(id <VBRequestRVIControllerDelegate>)delegate;

@end

Tell Typhoon to generate it:

- (id)rviControllerFactory
{
    return [TyphoonFactoryProvider withProtocol:@protocol(VBRequestRVIControllerFactory) dependencies:^(TyphoonDefinition* definition)
    {
        [definition injectProperty:@selector(rviView) withDefinition:[self requestRviView]];
    } returns:[VBRequestRVIViewController class]];
}

Expected Outcome:

Typhoon generates this factory

Actual Outcome:

2014-02-12 15:37:30.540 VoucherBlaster[1480:60b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: 'Tried to inject property 'rviView' on object of type 'VBRequestRVIControllerFactory__TyphoonAssistedFactoryImpl', but the instance has no setter for this property.'
*** First throw call stack:

Workaround:

Declare the factory as follow:

- (id)rviControllerFactory
{
    return [TyphoonFactoryProvider withProtocol:@protocol(VBRequestRVIControllerFactory) dependencies:^(TyphoonDefinition* definition)
    {
        [definition injectProperty:@selector(rviView) withDefinition:[self requestRviView]];
    } factory:^id(id <VBRequestRVIControllerFactory> factory, id <VBRequestRVIControllerDelegate> delegate)
    {
        return [[VBRequestRVIViewController alloc] initWithRviView:factory.rviView delegate:delegate];
    }];
}
@drodriguez
Copy link
Contributor

I’m pretty busy until next Tuesday. If you can use the workaround for now it will be great. Anyway, what you describe it’s very strange, because the properties part is “shared” between the implicit and the block versions, so it should fail the same way. I will try to build the test case and see what I find the next week.

@drodriguez drodriguez self-assigned this Feb 12, 2014
@jasperblues
Copy link
Member Author

Maybe it was a user error?

Yup, I can work around it. . . was just reporting now to make sure it gets logged.

@drodriguez
Copy link
Contributor

@jasperblues, can you test this again? I tried to reproduce it, and I don’t see how it could had happen? It will be strange, but you don’t have two different TyphoonFactoryProvider for VBRequestRVIControllerFactory, right?

I wrote my version of your classes in a gist if you want to see them.

@jasperblues
Copy link
Member Author

User error: I think I'd included extra properties on the factory interface, that Typhoon (correctly) didn't know how to inject.

. . . closing. . .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants