Translate

Swift: How to integrate UIView and UIViewController to SwiftUI View

1. Integrate UIView to SwiftUI View:

class UIViewExample: UIView {

}

struct SwiftView: UIViewRepresentable {
// update方法使我们能够将UIView和SwiftUI状态更新保持同步
func updateUIView(_ uiView: UIViewExample, context: Context) {
}

// make方法返回初始视图
func makeUIView(context: Context) -> UIViewExample {
}
}


2. Integrate UIViewController to SwiftUI View:

class UIViewControllerExample: UIViewController {

}

struct SwiftView : UIViewControllerRepresentable {
// Init your ViewController
func makeUIViewController(context: Context) -> some
    UIViewController {
let controller = UIViewControllerExample()
return controller
}
// No idea what to do here
func updateUIViewController(_ uiViewController:
    UIViewControllerType, context: Context) {

}
}