Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
}