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

Leonardo Cavalcanti
Leonardo Cavalcanti
5,308 Points

Incrementby challenge class object oriented swift basics

Help? It seems to work on Xcode

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

  init(width:Double, height:Double){
    self.width = width
    self.height = height
  }
  func incrementBy(points: Double){
  height = height + points
  width = width + points
  }
}

1 Answer

Jhoan Arango
Jhoan Arango
14,575 Points

Hello Leonardo:

So your method looks good, but you are giving the wrong values to width and points.

width = width + points is not going to work for this challenge.

try

width = points

Good luck

Kamran Ismayilov
Kamran Ismayilov
5,753 Points

Hello Jhoan, I did not get why are we assigning width to points? Can you please show me complete code and explain why you did so ? Appreciation in advance!

Jhoan Arango
Jhoan Arango
14,575 Points

Hello Kamran:

We are not assigning width to points, its the other way around. Points to width.

class Button {
  var width: Double
  var height: Double

  init(width:Double, height:Double){
    self.width = width
    self.height = height
  }
  func incrementBy(points: Double){
  height += points // Here we assign the points from the functions parameter.
  width += points
  }
}

Hope this answers your question.

Leonardo Cavalcanti
Leonardo Cavalcanti
5,308 Points

I don't think I gave the wrong values what you did is just a different way of doing the same thing... But thanks, it worked anyway...