Hello all,
I'm Michel and just getting acquainted with xcode and swift. I'm trying to get a simple webview to show a website.
And i have troubles for something that looks simple. Maybe its a bug or its something i'm doing wrong. Probably the last.
But with whether i run this code in xcode 8, 9.1 or the last beta.
I see the app but no website. When i run this code (with some modification for ios) its runnen like a charm.
Pure a osx app nothing works.
import Cocoa import WebKit class ViewController: NSViewController { @IBOutlet weak var mywebview: WKWebView! override func viewDidLoad() { super.viewDidLoad() let url = URL(string: "https://www.apple.com") let request = URLRequest(url: url!) mywebview.load(request) // Do any additional setup after loading the view. } }
I even tried to add WKWebView programmaticly.
I got one working test application where it works but all new demo apps with the same code same as above. result white screen no website.
import Cocoa import WebKit class ViewController: NSViewController, WKUIDelegate, WKNavigationDelegate { let webView = WKWebView() override func viewDidLoad() { super.viewDidLoad() self.webView.uiDelegate = self self.webView.navigationDelegate = self webView.frame = CGRect(x: 0, y: 0, width: 400, height: 270) view.addSubview(webView) let url = URL(string: "https://www.apple.com") let request = URLRequest(url: url!) webView.load(request) } }
I searched the web for examples, demo apps etc etc. but i find a lot of demo and examples for ios but not for osx.
I hope someone can point me to the right direction.
greetz Michel