IOS
SwiftUI
Using SwiftUI View from UIKit
3 min
in storyboard swiftui views can be used inside uikit apps by creating classes that conforms to uihostingcontroller with type of swiftui view we want use import swiftui struct testview view { var body some view { text("hello, world!") } } struct testview previews previewprovider { static var previews some view { testview() } } class testviewhostingcontroller uihostingcontroller\<testview> { required init?(coder adecoder nscoder) { super init(rootview testview()) } } create a class that conforms to uihostingcontroller with type of swiftui view in this case type is testview add required init?(coder adecoder nscoder) that calls super init(rootview testview()) , which creates uihostingcontroller with testview as rootview in storyboard add uihostingcontroller and set its class to the testviewhostingcontroller from code instantiate uihostingcontroller with the swiftui view as rootview present instantiated hosting controller like uiviewcontroller import swiftui let hostingcontroller = uihostingcontroller(rootview swiftuiview()) present(hostingcontroller, animated) // or navigationcontroller? pushviewcontroller(hostingcontroller, animated true)