Problem using loadHTMLString in Swift

I am trying to create an application that will clear data from a site and then load it. I managed to clean it up:

let task = URLSession.shared.dataTask(with: myURL) {(data, response, error) in

      

de-encode:

let newStr = String(data: data!, encoding: .utf8)

      

and i am trying to load it with

webView.loadHTMLString(newStr, baseURL:"")

      

But if I leave it blank, it just crashes and gives the following error:

fatal error: unexpectedly found nil while expanding an optional value

I am not sure what to set the baseURL because I am creating a string in the application.

Why install baseURL?

+3


source to share


1 answer


Instead of an empty line, ""

just use nil

like baseURL

.

Edit:



Now that you have determined that your webView is zero, the rest should be easy! Go to your code where you initialize the webView, add error messages to see why this fails. (nil webView means either failed initialization or you never initialized it ...)

+4


source







All Articles