SwiftUI reuse old items UIViewcontroller of Code (2020 edition Tutorial)
SwiftUI very easy to use, fast and efficient interface to develop, but specific to the operational level, with a history of code reuse is necessary to study the matter.
How to call in UIViewcontroller in SwiftUI
- 1. Create a Wrapper
For example, we have a Example1ViewController old code, we can start by creating a UIViewControllerRepresentable Wrapper
import Foundation
import SwiftUI
struct MKControllerWrapper: UIViewControllerRepresentable {
typealias UIViewControllerType = Example1ViewController
func makeUIViewController(context: UIViewControllerRepresentableContext<MKControllerWrapper>) -> MKControllerWrapper.UIViewControllerType {
return Example1ViewController()
}
func updateUIViewController(_ uiViewController: MKControllerWrapper.UIViewControllerType, context: UIViewControllerRepresentableContext<MKControllerWrapper>) {
//
}
}
- 2, you can call the Wrapper code in SwiftUI
NavigationLink( destination: MKControllerWrapper()){
Text(" Markdown文本编辑器 ")
.bold()
.foregroundColor(.white)
.background(Color.purple)
.cornerRadius(6)
.shadow(radius: 4)
}
effect
More attention SwiftUI tutorials and code columns
- Please pay attention to my column SwiftUI tutorials and source code