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: "")
    let myRequest = URLRequest(url: myURL!)
    webView.load(myRequest)
}}

But this shows the error:

No such module 'UIKit'

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

5
  • First of all your detail shows that you are working on MacOS app, but your Tittle is about UIKit.
  • APPKit MacOS development and UIKit is for iOS/TabOS.
  1. UIKit cannot be import for MacOS playground environment. Use AppKit
  2. If you are developing for iOS mobile environment and still face issue importing UIKit then you can follow following steps:

If you already selected iOS while creating Playground file but still getting error No such module 'UIKit', then follow following steps. Xcode 13

enter image description here

1
  • Open utilities from the top right corner
  • Change the platform to IOS

Then it should be okay to use UIKit

2

Check the 'show utilities' window. If the platform is set to MacOS, you'll get this error if you're calling UIKit. Same thing goes if your wanting IoS and your calling AppKit.


Check what device you are using. If you are using macOS instead of an iPhone 14, you will get this fault when you import UIKit. You do not have to reinstall Xcode.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.