Monday, September 30, 2024

What is UIHostingController?


UIHostingController- A UIKit view controller manages a SwiftUI view hierarchy. It is intended when integrating SwiftUI views into a UIKit view hierarchy.

 Present a SwiftUI view in the  UIKit view controller

let swiftCustomUIView = SwiftCustomUIView()
let hostingController = UIHostingController(rootView: swiftCustomUIView)
present(hostingController, animated: true, completion: nil)



What is SwiftUI?

SwiftUI is a user interface (UI) framework developed by Apple that differs from iOS frameworks in several ways,

  • Declarative
  • Compatibility 
  • Responsiveness (Reactive)
  • Preview Feature
  • Code Reusability
  • Reduced Code
UIKit is better for maintaining legacy apps and SwiftUI is a good choice for new projects.



Create a list in SwiftUI with sticky section headers

 Sample Code import SwiftUI struct ContentView : View {     @State var isCustomViewControllerDisplayed = false     @State private va...