Closed jlyonsmith closed 8 years ago
I guess you need to call instantiateViewControllerWithIdentifier
or instantiateInitialViewController
to get dependencies injected via the storyboard. I should update the document to describe the usage explicitly.
If you show me essence of your code, I might be able to give more accurate answer.
(I think you already know SwinjectStoryboard
in this repo is for Swinject v2. V1.x includes SwinjectStoryboad
by itself. )
OK, I finally got some time to dig into this. It appears the problem is my lack of understanding of what is actually going on with storyboard injection. It appears from SwinjectStoryboard.swift:90 that the UIVIewController is never actually saved in the container. The only place that you can get the controller is in the initComplete
call. Is that correct?
Yes, UIViewControllers are not stored in a container but just created and returned by calling factory closures, unless .Container
scope is specified.
The place you can access the view controllers is, as you told, initCompleted
which is the closure specified with registerForStoryboard
method in the storyboard injection.
That makes sense as you would generally want to avoid an unnecessary strong reference to the UIVIewController by holding on to it in the Container. Thanks!
I'm using Swinject 1.1.1. I really want to be able to inject a reference to my
UIViewController
which has been registered for storyboard injection. I currently have a SpriteKit app whereclass GameViewController: UIViewController
is injected intoMain.storyboard
viaregisterForStoryboard()
. Creating this view controller causes creation of a bunch ofSKScene
's one of which needs a reference to the originalGameViewController
in order to be able to callpresentViewController
to show settings. I tried toresolve
theGameViewController
in theinitComplete
(to avoid a circular reference) but it comes back asnil
. Am I missing something? Can this be made to work and if not, what's the underlying issue?