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 Inheritance Overriding Methods

Terrez dawson-holland
Terrez dawson-holland
1,656 Points

Stuck on the overriding methods challenge

The challenge wants me to override the increment by method for class RoundButton which I think I did but then it wants me to set a default parameter of 7.0 for points.. Do I need to use the init method?

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
    height += points
  }
}

class RoundButton: Button {
  var cornerRadius: Double = 5.0
 Override func incrementBy(points: Double){
  width += points
  height += points

  let points = points(7.0)
  }
}
Michael Pastran
Michael Pastran
4,727 Points

i think you are doing the last part wrong . your declaring a constant named "points" and assigning it the value of and instance of "points" with 7.0 as the parameter. i hope that makes sense. you have to remember that in the function icrementBy, "points" is a local parameter. its been a while since i did this challenge. but maybe you have to use a super.init?? lol let me know if i helped

1 Answer

Iulian Popescu
Iulian Popescu
1,363 Points

You don't have to use any init method. To declare a default value for a parameter you have just to follow the rule: nameOfMethod(parameterOne: Type = DefaultValue). Also Apple recommends that the parameters with default values should be placed at the end of parameters list. Good luck!