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 Improving Our User Interface Random Colors

I am getting an error message "variable used within its own initial value" import UIKit class ViewC

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var funFactButton: UILabel!
@IBOutlet weak var funFactLabel: UILabel!
let factModel = factModel()

override func viewDidLoad() {
    super.viewDidLoad()
    funFactLabel.text = factModel.getRandomFact()
}

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

@IBAction func showFunFact() {
    let randomColor = ColorModel().getRandomColor()
    view.backgroundColor =  randomColor
    funFactButton.tintColor = randomColor
  funFactLabel.text = factModel.getRandomFact()
}
William Crawford
William Crawford
4,319 Points

It looks like your third loin should read let factModel = FactModel() Try that.