Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value Xcode

0

Hi, I have an error in my Xcode project. I am trying to integrate the WebView logic to integrate the following code:

import UIKit
import WebKit


class ViewController: UIViewController {

    @IBOutlet weak var reser: WKWebView!
    @IBOutlet weak var produ: WKWebView!
    @IBOutlet weak var rp: WKWebView!
    @IBOutlet weak var anali: WKWebView!
    @IBOutlet weak var web: WKWebView!
    @IBOutlet weak var du: WKWebView!
    @IBOutlet weak var loginu: WKWebView!
    @IBOutlet weak var logoutu: WKWebView!

    override func viewDidLoad() {
        super.viewDidLoad()

        let reserr = URL(string: "https://google.com")
        let reserrr = URLRequest(url: reserr!)
        reser.load(reserrr)

        let produr = URL(string: "https://google.com")
        let produrr = URLRequest(url: produr!)
        produ.load(produrr)

        let rpr = URL(string: "https://google.com")
        let rprr = URLRequest(url: rpr!)
        rp.load(rprr)

        let analir = URL(string: https://google.com")
        let analirr = URLRequest(url: analir!)
        anali.load(analirr)

        let webr = URL(string: "https://google.com")
        let webrr = URLRequest(url: webr!)
        web.load(webrr)

        let dur = URL(string: "https://google.com")
        let durr = URLRequest(url: dur!)
        du.load(durr)

        let loginur = URL(string: "https://google.com")
        let loginurr = URLRequest(url: loginur!)
        loginu.load(loginurr)

        let logoutur = URL(string: "https://google.com")
        let logouturr = URLRequest(url: logoutur!)
        logoutu.load(logouturr)

    }


}

In the line where it says: reser.load(reserrr) Xcode gives me the following error:

  

Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

What is the solution to this problem?

Environment: Xcode 9 but the project was created with Xcode 10 Beta

Swift 4

    
asked by oscar alvarez gonzalez 21.07.2018 в 01:41
source

1 answer

0

Do you know what the optional values are? The URL type is optional, since it is an address to a file that may or may not exist. In the event that it does not exist or is not found, it will return nil , that is, a null value. That's why you call to reserve with an exclamation, to unpack the value of the variable. But this should only be done (in general) if you are sure that the value of the variable is not null. If the program unpacks the variable and is "without anything" it throws an error because it was expecting a value that you have assured it would be there.

Have you tried to change the code to see what fails, reserve or reserve?

    
answered by 21.07.2018 в 04:05