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 Object-Oriented Swift Classes and Objects Classes and Their Methods

Collin Keating
Collin Keating
1,797 Points

Does the method return anything? What is the amount of points? The instructions were a little scarce on this one. Help

Am I supposed to add a return value? Or not? Also, how many points do I increment by. Or does the user decide the amount of "points" to increment by?. Please help, the instructions left out a little bit of detail in my opinion.. Thank you !

Button.swift
class Button {
  var width: Double
  var height: Double

  init(width:Double, height:Double){
    self.width = width
    self.height = height
  }

  func incrementBy(points : Int){

  }

}

1 Answer

Jhoan Arango
Jhoan Arango
14,575 Points

Hello Collin:

Challenge:

We need to provide a means to increase the size of our Button. So we are going to add a method named incrementBy which will accept a parameter named points. (Within the method add points to the width and height properties).

lets break it down..

So we are going to add a method named incrementBy which will accept a parameter named points

func incrementBy(points: Double){}

Within the method add points to the wide and height properties

func incrementBy(points: Double){
      width += points // these are the properties 
      height += points
}

// We are using the local parameter name (points) to implement the method

This is how the challenge will look

class Button {
  var width: Double
  var height: Double

  init(width:Double, height:Double){
    self.width = width
    self.height = height
  }

  func incrementBy(points: Double){
  width += points
  height += points
    }
}

Hope this helps you understand a bit better, please let me know if you have any questions

Good luck

Collin Keating
Collin Keating
1,797 Points

Perfect! Thank you very much. Perfect explanation