krzysztofzablocki / Inject

Hot Reloading for Swift applications!
MIT License
2.14k stars 114 forks source link

Recommended way of using it with UIKit #7

Closed wojciech-kulik closed 2 years ago

wojciech-kulik commented 2 years ago

I'm trying to integrate the existing UIKit project with Inject. I wrapped ViewController with Inject.ViewControllerHost(...) and presented. I noticed that when I update ViewController it does hot-reload but doesn't call viewDidLoad.

We set up constraints and controls in viewDidLoad. Therefore, views and constraints are not reloaded until I leave the screen and show it again.

What is the recommended way of using it? Preferably without modifying ViewController.

wojciech-kulik commented 2 years ago

I've found the problem! I forgot that you are using autoclosure and I was doing something like this:

let module = builder.build()
rootViewController.pushViewController(Inject.ViewControllerHost(module), animated: true)

replacing it with:

let module = Inject.ViewControllerHost(self.builder.build())
rootViewController.pushViewController(module, animated: true)

solved the problem :)