Reputation: 113
The following is the code for importing local html file to swift playgrounds. It is not working but I'm getting a blank image in the Live View:
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
Upvotes: 1
Views: 773
Reputation: 70111
Copy the HTML file to the Playground's "Resources" folder (go to "Navigator" > "Show project navigator" to display the folder).
Then use Bundle.main.url(forResource:)
to fetch the file's URL, like this:
let u = Bundle.main.url(forResource: "Prac_1", withExtension: "html")
Upvotes: 3