What is WKWebView and how does it differ from UIWebView?
Answer
WKWebView is the modern web content display class (WebKit framework, iOS 8+). UIWebView was its predecessor — deprecated in iOS 12 and removed in iOS 15. Key differences: WKWebView runs in a separate process (out-of-process rendering) — more stable and secure; if the web content crashes, it doesn't bring down the app. UIWebView ran in the app process. WKWebView has significantly better JavaScript performance (Nitro JIT engine). WKWebView better memory efficiency — doesn't consume the app's memory budget as aggressively. UIWebView is DEPRECATED — any App Store submission using UIWebView gets rejected. WKWebView implementation: import WebKit class WebViewController: UIViewController, WKNavigationDelegate, WKUIDelegate { var webView: WKWebView! override func loadView() { let config = WKWebViewConfiguration() config.websiteDataStore = .nonPersistent() // Private browsing webView = WKWebView(frame: .zero, configuration: config) webView.navigationDelegate = self view = webView } override func viewDidLoad() { super.viewDidLoad() if let url = URL(string: "https://www.apple.com") { webView.load(URLRequest(url: url)) } } // Navigation delegate: func webView(_ wv: WKWebView, didStartProvisionalNavigation _: WKNavigation!) { print("Loading: \(wv.url?.absoluteString ?? "")") } func webView(_ wv: WKWebView, didFinish _: WKNavigation!) { title = wv.title } } // JS communication: webView.evaluateJavaScript("document.title") { result, _ in print(result) } webView.configuration.userContentController.add(self, name: "native").
Previous
What is the difference between frame-based and Auto Layout?
Next
What is push notifications and APNs in iOS?