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 View Controllers and Views Creating IBOutlets

I don't know what I am doing wrong.

Even though Xcode will generate the code for IBOutlets automatically, it's good to be familiar with the syntax. In the editor below, you have a UIViewController subclass.

Your task is to add an IBOutlet stored property to the class named textLabel of type UILabel. Remember that IBOutlets are generated with an exclamation mark at the end.

ViewController.swift
class ViewController: UIViewController {

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

  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  } @IBOutlet weak var textLabel: UILabel!
}

1 Answer

David Papandrew
David Papandrew
8,386 Points

Here is the code with correct placement of the textLabel:

class ViewController: UIViewController {
  @IBOutlet weak var textLabel: UILabel!

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

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

Even though the code looks different than previous Swift examples, you are still working with a class. In this case, it's a class called "ViewController". The layout of the class will still be like other classes you are familiar with. And the textLabel is essentially a stored property of the class.

Namely:

class sampleClass {
  //Stored properties go here: e.g. variables/constants

  //Init methods can go here (if needed)

  //Class methods go here
}