imagine a ViewController which is comprised of multiple child ViewControllers as depicted below:
ViewController1:
- ViewController2
- ViewController3
ViewController2 does not change so it is defined on the Storyboard with containerViews. In order to get reference of ViewController2 by ViewController1 I do the following:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let destination = segue.destination
if let viewController2 = destination as? ViewController2 {
self.viewController2 = viewController2
}
}
As for ViewController3, it is dynamic so it is added programmatically in ViewController1 like so:
addChildViewController(viewController3)
view.addSubview(viewController3.view)
viewController3.didMove(toParentViewController: self)
My question is, for both these scenarios, what is the proper way of handling the memory management of the references of viewController2 and viewController3. Should they be weak or strong references?
Thanks!