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 Improving Our User Interface Changing the Background Color

SOMEONE PLEASE HELP

Have been stuck here and cannot get this to pass. Do not know what to type in please explain

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.
  }
}

2 Answers

Alphonso Sensley II
Alphonso Sensley II
8,514 Points

Hi Eddie. Glad my explanation helped you! For part two Pasan explains it pretty well at 3:38 in the video "Adding a Pop of Color". Watch this again to try to get an understanding of whats happening.

Basically we are "assigning" the instance of UIColor.blue that we previously created to the backgroundColor of our view. We want this to happen as soon as our view loads. Hence we place the code inside of the viewDidLoad function.

class ViewController: UIViewController {


var blueColor = UIColor.blue
  override func viewDidLoad() {
      super.viewDidLoad()
      // Do any additional setup after loading the view, typically from a nib.
      let blueColor:UIColor

     view.backgroundColor = UIColor.blue
  }

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

YOU ARE THE MAN... I wasn't to far off, instead of typing view.backgroundColor = UIColor.blue, I typed view.backgroundColor = blueColor

Alphonso Sensley II
Alphonso Sensley II
8,514 Points

Hello Eddie Aguilar , It can be a little tricky to get at first. But as you keep up the practice it will become familiar to you!

Here is a guide from Apple on Properties that me be helpful for you. https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Properties.html Also try rewatching the "Adding a Pop of Color" video the precedes this challenge.

When I did these challenges I try to think of the challenge instructions as "pseudo code" The instructions are really dropping hints for what needs to be done in code. For example; where the instructions read "Add a stored property to the view controller named blueColor and assign an instance of UIColor as the default value." We can break down those instructions:

1) Add a stored property named blueColor. So we need "var blueColor"

2) Assign an instance of UIColor as the default value. These instruction let us know we need var blueColor = UIColor.blue

3) blueColor needs a type. So we add var blueColor: UIColor to viewDidLoad

Im trying to get better at explaining things and I hope this makes sense.

Can I ask that you assist me with part 2 of this video. I like the way you explained it the first time??

Mr. Sensley the 2nd can i ask you a favor. I just posted a new question and was curios to know if YOU would mind answering it.