Whenever I try to use the below code snippet in our existing UIKit project, I get the following error. When I move the same code to another Xcode project, it works perfectly. On clicking Xcode suggestion same function get added but with same error again.
Type 'MyUIKitViewControllerWrapper' does not conform to protocol 'UIViewControllerRepresentable'
import Foundation
import SwiftUI
struct MyUIKitViewControllerWrapper: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> MyUIKitViewController {
return MyUIKitViewController()
}
func updateUIViewController(_ uiViewController: MyUIKitViewController, context: Context) {
}
}
import Foundation
import UIKit
// Create your UIKit view controller
final class MyUIKitViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Set up your UIKit view controller
let label = UILabel()
label.text = "Hello from UIKit!"
label.textAlignment = .center
label.frame = CGRect(x: 0, y: 0, width: 200, height: 50)
view.addSubview(label)
}
}