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

@objection_initializer not passing arguments #83

Open
drekka opened this issue Jan 24, 2015 · 2 comments
Open

@objection_initializer not passing arguments #83

drekka opened this issue Jan 24, 2015 · 2 comments

Comments

@drekka
Copy link

drekka commented Jan 24, 2015

I have the following initialiser in a class:

objection_initializer(initWithComms:)
-(instancetype) initWithComms:(Comms *) commsX {
    self = [super init];
    if (self) {
        _comms = commsX;
    }
    return self;
}

However when I run the code the commsX argument is nil. I've tried to follow the Objection code and it appears that it is building an instance of the Comms object and putting it into it's context. However it's not passed through to the code that actually creates the instance of this code.

Am I doing anything wrong? I found the sample code on the Objection website rather difficult to follow :-(

@StatusReport
Copy link

By using objection_initializer you define that this is the initializer that will be called when you fetch it from the injector (or factory), but you need to either provide default arguments (additional arguments to objection_initializer) or to use getObjectWithArgs: / getObject:arguments: / getObject:argumentList: and provide the arguments.

Note that the downside of fetching objects in that manner is that you lose type safety, and that you cannot provide primitive objects as arguments.

@drekka
Copy link
Author

drekka commented Jan 26, 2015

Ahh, ok. I thought that Objection would look at the arguments and then look for matching objections in it's context.

When I was debugging through trying to see how it works, I saw Objection load the Comms singleton first. Then when it went to can the initWithComms, I could see the Comms object in the _context variable of the code that was doing the loading. So it looked like Objection could have set it into the arguments array it was passing to the load code. Presuming it could examine the init's signature and deduce what it was looking for.

As there isn't anywhere in the code where Comms is initialised (It's currently being handled by Objection) I was hoping it would be able to figure this out by itself.

Anyway. I'll have a play and see how I go. Thanks :-)

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