Web View deprecated?

Thanks for the quick reply!

I went ahead and used WKWebView - all I had to do was:

  • Import WebKit

  • Replace the UIWebView @IBOutlet with WKWebView

  • Paste in the code from Ch. 7.

  • Accept XCode’s suggested autofix:
    textEncodingName → characterEncodingName.

I used this as reference:
https://developer.apple.com/documentation/webkit/wkwebview

//
//  AboutViewController.swift
//  BullsEye
//
//  Created by Christopher Clark on 14/10/2017.
//  Copyright © 2017 Christopher Clark. All rights reserved.
//

import UIKit
import WebKit

class AboutViewController: UIViewController {

    @IBOutlet weak var webView: WKWebView!
    
    @IBAction func close() {
        dismiss(animated: true, completion: nil)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        if let url = Bundle.main.url(forResource: "BullsEye",
                                     withExtension: "html") {
            if let htmlData = try? Data(contentsOf: url) {
                let baseURL = URL(fileURLWithPath: Bundle.main.bundlePath)
                webView.load(htmlData, mimeType: "text/html",
                             characterEncodingName: "UTF-8",
                             baseURL: baseURL)
            }
        }
    }
}
5 Likes