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

Creating IBOutlets - Build a Simple iphone app with swift 2.0

I'm having issues setting funfactlabel.text equal to "an interesting fact". Everytime I try to add the line of code I get an error saying "expected declaration". Here is what my code looks like without the funfactlabel.text code:

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

}
@IBOutlet var funfactlabel: [UILabel]!

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

}

1 Answer

Hey Brooke,

Try placing the IBOutlet for the label at the very top of the ViewController class. The complier may not recognize the declaration because you're using the method on something the compiler hasn't established yet just because the declaration comes after the use.