Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Aaryen Singh
Aaryen Singh
1,688 Points

Help please with - Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

HI I'm getting this error: 2019-05-05 13:55:01.709309+0100 FunFacts[26757:959593] Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

my app builds succeeds and then crashes when loading with this error. my code is this on the error page

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var funFactLabel: UILabel!
let factProvider = FactProvider()

override func viewDidLoad() {
    super.viewDidLoad()

    funFactLabel.text = factProvider.randomFact()
}

@IBAction func showFact() {
 funFactLabel.text = factProvider.randomFact()

} }

The error is on line: funFactLabel.text = factProvider.randomFact() Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

2 Answers

The problem is that you probably deleted the label at some point and than add it back to the storyboard.

Hover your mouse on the circle next to @IBoutlet weak var funFactLabel: UILabel!, the label should highlight. If it doesn't right click on the label and drag form the "New referencing outlet" to @IBOutlet weak var funFactLabel: UILabel! in your viewController class.

Aaryen Singh
Aaryen Singh
1,688 Points

Thank you, it has helped me!