xcodeswiftui

Undeclared type 'UIViewRepresentable' in MacOS project


I create macOS project and I try to make UIViewRepresentable but get this error.

import SwiftUI

struct WebView: UIViewRepresentable { //Error: Use of undeclared type 'UIViewRepresentable'
}

What can I do with it or how can I make my own UIViewRepresentable for macOS to use WKWebView in my project?

struct WebView: UIViewRepresentable {
    func makeUIView(context: Context) -> WKWebView {
        WKWebView()
    }

    func updateUIView(_ uiView: WKWebView, context: Context) {
    }
}

Solution

  • UI... refers always to UIKit.

    For macOS you have to use NSViewRepresentable