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

AJ Thomas
AJ Thomas
249 Points

Can anybody help me with the next question it is confusing me i am trying to do it right but it says i'm wrong

Can somebody please tell me the code or tell me what I'm doing wrong

6 Answers

J.D. Sandifer
J.D. Sandifer
18,813 Points

Please post your code and the error you're receiving. It's hard to help you fix it if we have no idea what your current answer looks like.

J.D. Sandifer
J.D. Sandifer
18,813 Points

Look at the initializer function init(). This function sets the height and width of the Button object based on two parameters passed to it. By looking at that function we can remind ourselves of 3 things: 1) to assign a value to the height and width of the Button, we need to use self.width and self.height, 2) the name of the incoming parameters is the word before the ":", because that's how they're referred to later, and 3) we don't use "Double" again after the list of parameters - it's the type, remember?

So base on those things, we should end up with code something like this:

class Button {
  var width: Double
  var height: Double

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

  func incrementBy(points:Double){
    self.width = self.width + points // points is the variable name, not Double - that's the type
    self.height = self.height + points // we could use += here instead, but it looked like you got
                                       // confused about the order - it would be self.height += points
  }
}
AJ Thomas
AJ Thomas
249 Points

how do i do that JD.Sandifer

J.D. Sandifer
J.D. Sandifer
18,813 Points

Just highlight all of you code - like any other text - and hit Ctrl (or Cmd) + C to copy. Then come here and hit Ctrl/Cmd + V to paste into your question text box. There are other, more elegant ways, but that's the simplest.

Also, there should be a video on the right side of the screen whenever you're in the forums - under "Tips for asking questions". You might take a look at that later because it lists the other ways to share the code.

AJ Thomas
AJ Thomas
249 Points

Ok I haven't wrote any code because it all got deleted one time when I came back on here so now I have nothing and I don't even know how to start it off but this is what I have: class Button { var width: Double var height: Double

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

func incrementBy (points: Double) Double += Height Double += Width } } J.D. Sandifer

Here is the solution :

class Button {
  var width: Double
  var height: Double

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

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

}
AR Ehsan
AR Ehsan
7,912 Points

class Button { var width: Double var height: Double

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

func incrementBy (points:Double) { width = width + points height = height + points } } Please tell if that helps!