HomeiOS Developmentios - Is it greatest to make use of a number of...

ios – Is it greatest to make use of a number of UIHostingControllers for nesting a number of SwiftUI views inside a UIViewController?


Beneath is the way you add a SwiftUI view to a UIViewController.

Nonetheless, I’ve not seen any examples the place somebody provides two separate SwiftUI views to the identical UIViewController.

Is the beneath strategy advisable? I am involved that including a number of UIHostingController kids may develop into reminiscence intensive.

import UIKit
import SwiftUI

class CentralVC: UIViewController {
    
    lazy var rectangleView: UIView = {
        let internet hosting = UIHostingController(rootView: Rectangle().foregroundStyle(.orange))
        addChild(internet hosting)
        internet hosting.didMove(toParent: self)
        return internet hosting.view
    }()
    
    lazy var tabBarView: UIView = {
        let internet hosting = UIHostingController(rootView: TabBarView())
        addChild(internet hosting)
        internet hosting.didMove(toParent: self)
        return internet hosting.view
    }()
    
    override func viewDidLoad() {
        tremendous.viewDidLoad()
        view.addSubview(rectangleView)
        view.addSubview(tabBarView)
        //viewDidLoad code
    }
    
    //And so forth
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments