2

I not familiar with storyboards, i have superclass for UIViewController, that have init method like that:

 convenience init(viewModel: Any){
        self.init()
        self.viewModel = viewModel
    }

So, when viewDidLoad is called, i already have viewModel that is not nil.

And i can easy create view controller with model like that:

let pvc = ProductViewController(viewModel: pvm)
self.navController?.pushViewController(pvc, animated: true)

How to add this capability to storyboards? What i want is, pass model to constructor, to be sure that when viewDidLoad is called model is exist.

Evgeniy Kleban
  • 6,794
  • 13
  • 54
  • 107
  • Why do you need to pass the model before `viewDidLoad`? I understand that in macOS where Cocoa Bindings expect values right after the initialization. But what functionality in iOS requires valid values before `viewDidLoad`? Isn't a shared class (singleton) an option? – vadian Oct 11 '17 at 16:30

1 Answers1

2

Unfortunately there's no way to do this with storyboards as view controllers are initialized beforehand.

I wrote a post on making view controller and view model associations more explicit though.

shanev
  • 38
  • 4