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
Farhan Hussain
13,928 PointsWorks on Xcode but not here. Help!
Question: 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.
My code:
class ViewController: UIViewController {
@IBOutlet weak var textLabel: UILable!
override func viewDidLoad() {
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
// Dispose of any resources that can be recreated
}
}
I'm wrong because I'm not adding it to a class named textLabel? But I can't find it or do I have to create one?
Farhan Hussain
13,928 Points2 Answers
Tassia Castro
iOS Development Techdegree Student 9,170 PointsAhhh, It was just a typo Farhan. Try this way
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var totalLabel: UILabel! // I replaced 'UILable' for 'UILabel'
override func viewDidLoad() {
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
// Dispose of any resources that can be recreated
}
}
Farhan Hussain
13,928 PointsThank you I realized my mistake, and it should be textLabel not totalLabel :)
Tassia Castro
iOS Development Techdegree Student 9,170 PointsOhh, you're right =)
Tassia Castro
iOS Development Techdegree Student 9,170 PointsHey Farhan,
Have you added: import UIKit on top of the class? UILable is part of UIKit framework so in order to use it you have to import UIKit.
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var textLabel: UILable!
override func viewDidLoad() {
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
// Dispose of any resources that can be recreated
}
}
Farhan Hussain
13,928 PointsI added import UIKit but it still doesn't work :/. Not sure what to do now. Maybe is it because of the placement of the IBOutlet?
Tassia Castro
iOS Development Techdegree Student 9,170 PointsTassia Castro
iOS Development Techdegree Student 9,170 PointsCan you share the link of the question here?