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

Fatal Error Message

The code I've written for "Build a Simple iPhone App with Swift 3" keeps bringing up the error message: "fatal error: unexpectedly found nil while unwrapping an Optional value (lldb) ". My code is below.

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var funFactLabel: UILabel!
let facts = ["Ants stretch when they wake up in the morning", "Ostriches can run faster than horses"]

override func viewDidLoad() {
    super.viewDidLoad()

    funFactLabel.text = facts[0] //This is where the error message is coming from
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBAction func showFact() {
    funFactLabel.text = facts[1]
}

}

Someone please help me figure out what's going on!

1 Answer

Hey Rebekah Bae,

For future questions, it would be more helpful if you posted the full error message so we can see what's happening here. Without this, I'm going to guess your problem is that your ViewController has an orphaned outlet in its Storyboard file.

To solve this:

Select your ViewController in the Storyboard file and at the top of it, CTRL+click on the Yellow Icon on the far left. If you see any Yellow ! Warnings, this means you have unconnected outlets or actions and need to either delete them or reconnect them.

Also, make sure your original IBOutlet for the funFactLabel is connected. If it is, there will be a filled in dot to the left of the line number for that outlet in code.

Let me know if this helps.

Good Luck