fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

Fabrizio

I get an error when I press a button on the sideBar stopping here:

webView.scalesPageToFit = true
webView.loadRequest(request)

I would like to ask help to solve the problem. Below is my code of ViewController.swift

import UIKit

class ViewController: UIViewController, UISearchBarDelegate {
    @IBOutlet weak var searchBar: UISearchBar!
    @IBOutlet weak var webView: UIWebView!

    override func viewDidLoad() {
        super.viewDidLoad()

        let url = NSURL(string: "http://www.apple.com")
        let request = NSURLRequest(URL: url!)

        webView.scalesPageToFit = true
        webView.loadRequest(request)
    }

    func searchBarSearchButtonClicked(searchBar: UISearchBar! {
        caricaUrl(searchBar.text)
    }

    func caricaUrl(url: String) {
        let url = NSURL(string: "http://www.google.com/search?q=" + "\(url)")

        let request = NSURLRequest(URL: url!)

        webView.scalesPageToFit = true
        webView.loadRequest(request)
    }

    func didReceiveMemoryWaarning() {
        super.didReceiveMemoryWarning()   
    }


    @IBAction func onBurger() {
        (tabBarController as TabBarController).sidebar.showInViewController(self, animated: true)
    }

}
Wiem

Your web view is an optional value, so you either have to force unwrap it or say that it is an optional when calling it. Your app was trying to force unwrap it, and it came back with nil. That means you can't force unwrap the variable.

So you can change both of these lines in both places they are declared:

webView.scalesPageToFit = true
webView.loadRequest(request)

to these lines:

webView?.scalesPageToFit = true
webView?.loadRequest(request)

The question mark explicitly says that the webView variable is an optional.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

From Dev

fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

From Dev

fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

From Dev

fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

From Dev

Swift fatal error: unexpectedly found nil while unwrapping an Optional value (lldb) in Tableview

From Dev

swift: fatal error: unexpectedly found nil while unwrapping an Optional value (lldb), Thread 1

From Dev

ios - fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

From Dev

swift fatal error: unexpectedly found nil while unwrapping an Optional value(lldb)from email -in my code?

From Dev

AVCaptureSession Runtime crash. fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

From Dev

Swift 2.0 fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

From Dev

Swift Sliders - fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

From Dev

fatal error: unexpectedly found nil while unwrapping an Optional value swift

From Dev

.reloadData() fatal error: unexpectedly found nil while unwrapping an Optional value

From Dev

fatal error: unexpectedly found nil while unwrapping an Optional value

From Dev

swift fatal error: unexpectedly found nil while unwrapping an Optional value

From Dev

reloadData() fatal error: unexpectedly found nil while unwrapping an Optional value

From Dev

fatal error: unexpectedly found nil while unwrapping an Optional value swift

From Dev

Weird "fatal error: unexpectedly found nil while unwrapping an Optional value"

From Dev

fatal error: unexpectedly found nil while unwrapping an Optional value Computation

From Dev

fatal error: unexpectedly found nil while unwrapping an Optional value (Swift)

From Dev

CLLocationManager - fatal error: unexpectedly found nil while unwrapping an Optional value

From Dev

fatal error: unexpectedly found nil while unwrapping an Optional value in didDeselectRowAt

From Dev

fatal error: unexpectedly found nil while unwrapping an Optional value - delegate

From Java

Fatal error: unexpectedly found nil while unwrapping an Optional values

From Dev

Swift - While playing sound I get error "fatal error: unexpectedly found nil while unwrapping an Optional value"

From Dev

Getting nil values using NSDate (fatal error: unexpectedly found nil while unwrapping an Optional value)

From Dev

Fatal error while taking snapshot of view: unexpectedly found nil while unwrapping an Optional value

From Dev

fatal error: unexpectedly found nil while unwrapping an Optional value while filtering

From Dev

"fatal error: unexpectedly found nil while unwrapping an Optional value" while creating UIImage from NSData

Related Related

  1. 1

    Fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

  2. 2

    fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

  3. 3

    fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

  4. 4

    fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

  5. 5

    Swift fatal error: unexpectedly found nil while unwrapping an Optional value (lldb) in Tableview

  6. 6

    swift: fatal error: unexpectedly found nil while unwrapping an Optional value (lldb), Thread 1

  7. 7

    ios - fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

  8. 8

    swift fatal error: unexpectedly found nil while unwrapping an Optional value(lldb)from email -in my code?

  9. 9

    AVCaptureSession Runtime crash. fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

  10. 10

    Swift 2.0 fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

  11. 11

    Swift Sliders - fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

  12. 12

    fatal error: unexpectedly found nil while unwrapping an Optional value swift

  13. 13

    .reloadData() fatal error: unexpectedly found nil while unwrapping an Optional value

  14. 14

    fatal error: unexpectedly found nil while unwrapping an Optional value

  15. 15

    swift fatal error: unexpectedly found nil while unwrapping an Optional value

  16. 16

    reloadData() fatal error: unexpectedly found nil while unwrapping an Optional value

  17. 17

    fatal error: unexpectedly found nil while unwrapping an Optional value swift

  18. 18

    Weird "fatal error: unexpectedly found nil while unwrapping an Optional value"

  19. 19

    fatal error: unexpectedly found nil while unwrapping an Optional value Computation

  20. 20

    fatal error: unexpectedly found nil while unwrapping an Optional value (Swift)

  21. 21

    CLLocationManager - fatal error: unexpectedly found nil while unwrapping an Optional value

  22. 22

    fatal error: unexpectedly found nil while unwrapping an Optional value in didDeselectRowAt

  23. 23

    fatal error: unexpectedly found nil while unwrapping an Optional value - delegate

  24. 24

    Fatal error: unexpectedly found nil while unwrapping an Optional values

  25. 25

    Swift - While playing sound I get error "fatal error: unexpectedly found nil while unwrapping an Optional value"

  26. 26

    Getting nil values using NSDate (fatal error: unexpectedly found nil while unwrapping an Optional value)

  27. 27

    Fatal error while taking snapshot of view: unexpectedly found nil while unwrapping an Optional value

  28. 28

    fatal error: unexpectedly found nil while unwrapping an Optional value while filtering

  29. 29

    "fatal error: unexpectedly found nil while unwrapping an Optional value" while creating UIImage from NSData

HotTag

Archive