xcodemacoswkwebview

No such module 'UIKit'


All I want to do is make the most basic macOS / OS X app that just shows a WKWebView...

import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate {

var webView: WKWebView!

override func loadView() {
    let webConfiguration = WKWebViewConfiguration()
    webView = WKWebView(frame: .zero, configuration: webConfiguration)
    webView.uiDelegate = self
    view = webView
}
override func viewDidLoad() {
    super.viewDidLoad()
    
    let myURL = URL(string: "https://www.apple.com")
    let myRequest = URLRequest(url: myURL!)
    webView.load(myRequest)
}}

But this shows the error:

No such module 'UIKit'


Solution

  • UIKit is for mobile apps, not MacOS apps. You want AppKit.