create wkwebview in swift

To create a WKWebView in Swift, first you need to import the WebKit framework. Then, you can create a WKWebView instance programmatically or using Interface Builder.

Here is an example of creating a WKWebView programmatically in Swift:

main.swift
import UIKit
import WebKit

class ViewController: UIViewController {

    var webView: WKWebView!

    override func viewDidLoad() {
        super.viewDidLoad()

        webView = WKWebView(frame: view.bounds)
        view.addSubview(webView)

        if let url = URL(string: "https://www.google.com") {
            webView.load(URLRequest(url: url))
        }
    }
}
370 chars
19 lines

In this example, we create a WKWebView instance, set its frame to fill the entire view, and add it as a subview of the view controller's view. Then, we load a URL request into the web view using the load method.

Note that you also need to add the WebKit.framework to your project in order to use WKWebView.

gistlibby LogSnag