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

Martin Franzner
Martin Franzner
3,300 Points

Points to width

it says width is not in the property with points, but in the xcode works for me, or am I doing other thing that is not asking, please if someone could help me

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) {
      width = points

  }
}

let size = Button(width: 10, height: 10)

1 Answer

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Martin,

There's nothing technically wrong with your code, which is why it works in Xcode. However, it's not doing what the challenge is asking for; the challenge wants you to create a method that increases the value of both the width and the height by the points supplied to the method. What you've done is simply set the value of the width to whatever points are supplied.

For example, if we had a Button instance with a width of 50 points and a height of 20 points, calling incrementBy(10) on that instance should change the width to 60 points and the height to 30 points.

Here's how you would do it:

increment.swift
  func incrementBy(points: Double) {
    self.width += points
    self.height += points
  }