Swinject / SwinjectStoryboard

Swinject extension for automatic dependency injection via Storyboard
MIT License
268 stars 141 forks source link

Avoiding duplicate "completed" calls #64

Closed atomicbird closed 6 years ago

atomicbird commented 7 years ago

I'm using a SwinjectStoryboard extension to set up injection for my main VC. That's working fine. I added the following to set up injection for another VC in the same storyboard. This view controller is reached by a segue from the initial view controller:

defaultContainer.storyboardInitCompleted(DetailViewController.self) { (r:Resolver, c:DetailViewController) in
    c.bar = "Injected bar"
}

[I'm trying out SwinjectStoryboard with Xcode's default master/detail view app template, in case that's not obvious.]

Here's the thing: With the above code, injection works, but the closure is called twice with different instances of DetailViewController. The first is when setup() is called, and the second is when the DetailViewController appears on the screen. If I set a breakpoint in the closure, c is a different instance in the second call, and it's the second one that appears. I don't know why the first is created or what happens to it.

Why do I get two calls to this closure with different instances, and how would I avoid that?

yoichitgy commented 6 years ago

Does v1.1.2 reproduce the issue?

jakubvano commented 6 years ago

Closing due to lack of activity. @atomicbird If you still have questions, feel free to reopen this 😉