The app I'm working on is predominantly in UIKit. We are starting to shift to SwiftUI for smaller components and I wanted to write a neat little extension which would take in a SwiftUI view and return the UIKit view. This is the code I currently have:
static func getUIView(for swiftUIView: View) -> UIView {
let hostingController = UIHostingController(rootView: swiftUIView)
return hostingController.view
}
}
However this throws an error
Protocol 'View' can only be used as a generic constraint because it has Self or associated type requirements
Could someone explain to me why this is a problem and what would be the right way of achieving this?