I'm migrating an app from Storyboards and UIKit to SwiftUI. It's a big app, so I am doing it in stages. Specifically, I am embedding a few old UIKit assets within SwiftUI using UIViewControllerRepresentable.
I'm loading a UIViewController from the storyboard using
let storyboard = UIStoryboard(name: "MainStoryboard", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "MyViewController") as! MyViewController
This works fine except that the instantiated MyViewController does not contain the sub views that are present in the storyboard / interfacebuilder. Is there a way to instantiate the view controller with the sub views?
print(vc.view.subviews)to your code to confirm that you are getting some other view controller that really doesn't have subviews.vc.view.subviewsbut are not shown on the screen. The problem is that they were not placed correctly because the constraints got messed up in the process.UIViewControllerRepresentableis tricky to get right and even some of Apple's examples have mistakes. Maybe you could share your code for that? Gettingupdateandmakecorrect are essential