Use of undeclared type 'UIViewRepresentable' in macOS project

Hi,


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) {
  }
}


My question on stackoverflow

Replies

UIViewRepresentable is for UIKit (iOS). You'll want NSViewRepresentable (see "AppKit Hosting" at https://developer.apple.com/documentation/swiftui/framework_integration).

Alternatively use the macCatalyst APIs which make UIView available under macOS. To enable this you have to explicitly set the app's target architecture to be macCatalyst instead of macOS.