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 Build a Simple iPhone App with Swift 2.0 Structs as Data Models Creating a Data Collection

Can't add text to a stored property?

I get an error saying 'bad instruction' when trying to run my app from the line of code below: funFactLabel.text = [0]

I receive this error when I try to add any text to the funFactLabel stored property. Any idea why?

import UIKit

class ViewController: UIViewController {

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

    override func viewDidLoad() {
        funFactLabel.text = facts[0]

    override func didReceiveMemoryWarning() {

1 Answer

Greg Kaleka
Greg Kaleka
39,021 Points

Hm... tough to diagnose this error without being able to poke around in the code. My first step would be to make sure your @IBOutlet is correctly hooked up to your storyboard. Easiest way to check this is to go into your storyboard, select the label, and open the connections inspector in the right sidebar (the -> icon all the way to the right).

Report back if that was your issue!

The "Show another fun fact" label has Touch Up Inside connected to View Controller showFunFact.

The "Some fact goes here" label has no connections.

Greg Kaleka
Greg Kaleka
39,021 Points

Not sure what to make of it. I would probably download the project files Pasan provides, and compare your code to see if there are any discrepancies. Assuming you have a closing curly brace, the code you've pasted here looks fine.