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

funFactLabel.text

Value of type 'UIButton' has no member 'text'

I entered the code below in xcode (from the video) and received the above error. Can anyone help?

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var funFactLabel: UIButton!

override func viewDidLoad() {
    super.viewDidLoad()
    funFactLabel.text = "An interesting fact!"

}

1 Answer

Steven Deutsch
Steven Deutsch
21,046 Points

Hey John Power,

This is because you did not create a label, you created a button. You need to delete an recreate this IBOutlet as a UILabel. You also need to delete the reference to this outlet in the storyboard. Basically, delete it from your storyboard and in your viewController file. Recreate the outlet on a UILabel instead.

// Problem is here
@IBOutlet weak var funFactLabel: UIButton! // <--- needs to be a UILabel!

override func viewDidLoad() {
    super.viewDidLoad()
    funFactLabel.text = "An interesting fact!"

}

Good Luck!

That worked! Thanks Steven!