如何将本地 HTML 文件导入我的 Swift Playground Live View?

How Do I import a local HTML file to my Swift Playground Live View?

以下是将本地html文件导入swift游乐场的代码。它不工作,但我在实时视图中看到一张空白图像:

import UIKit
import WebKit
import PlaygroundSupport
let u = URL(string: "Prac_1.html")
let request:URLRequest = URLRequest(url: u!) 
let webView=UIWebView(frame:CGRect(x:0,y:0,width:768.0,height:1024.0))
webView.loadRequest(request) //Loading the request
PlaygroundPage.current.liveView = webView

将 HTML 文件复制到 Playground 的 "Resources" 文件夹(转到 "Navigator" > "Show project navigator" 以显示该文件夹)。

然后使用Bundle.main.url(forResource:)获取文件的URL,像这样:

let u = Bundle.main.url(forResource: "Prac_1", withExtension: "html")