Mac OS Webview HTML string is blank

Here is the simple code that works in xcode 8 but does not work(blank screen) on Xcode 9. Tried changing App Transport settings - Allow Arbitary loads to “YES”. Still not working.
Any suggestions on how to fix this?

import UIKit
import WebKit

class ViewController: UIViewController {

@IBOutlet weak var webview: WKWebView!
override func viewDidLoad() {
webview.loadHTMLString(“Hello HTML String”, baseURL: nil)

@nhr Thanks very much for your question. Have you tried loading a webpage inside the URL? Try that first, and see if you can load a page like

Syed, Thanks for your suggestion. Still get a blank screen for It works fine in IOS and XCode 8, but not in Xcode 9.

Try this sample code:

@IBOutlet weak var webView: WKWebView!
    override func viewDidLoad() {
        // Do any additional setup after loading the view, typically from a nib.
        let url = NSURL (string: "");
        let request = NSURLRequest(URL: url!);


This works fine on storyboard created using Xcode 8. But if you create the storyboard using Xcode 9, I still get a blank screen. See if you test this on a storyboard created using Xcode 9.

Thanks for your help.


This topic was automatically closed after 166 days. New replies are no longer allowed.