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 What is Inheritance?

Dominic Bryan
Dominic Bryan
14,452 Points

Do not understand challenge, doing everything the way it is done in the video but no good! HELP

It is part 3 of the challenge and this is what it asks,

Create an instance of the class RoundButton and name the instance rounded.

class Button {
  var width: Double
  var height: Double

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

class RoundButtons: Button {
  var cornerRadius = 5.0
}

var rounded = RoundButtons(width: 10.0, height: 10.0)

This is my code, at the bottom you can see I have created an instance of RoundButton and stored it int he var rounded.

It tells me code could not be compiled, and when clicking preview to see what it says it doesn't show anything.

Help please, Thank you in advance

I know you posted your question 2 months ago but I found the error anyways ;-) You have a typo in your code. The class should be named RoundButton! You named it RoundButtonS

Chris Shaw
Chris Shaw
26,676 Points

Martin Langeder, I already mentioned that in my answer below :smile:

2 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi Dominic,

Currently you have the plural version of RoundButton, simply drop the s from the end on both your class and instance assignment and you should be good to go.

class RoundButton: Button {
  var cornerRadius = 5.0
}

var rounded = RoundButton(width: 10.0, height: 10.0)

Happy coding!

Dominic Bryan
Dominic Bryan
14,452 Points

Thanks Chris, embarrassing how I miss such little things -_-

Chris Shaw
Chris Shaw
26,676 Points

No worries, and no need to be embarrassed, after 5 years building websites I still miss the smaller things.

I am working on the same problem and am wondering where the 10.0 comes from? I am also wondering why RoundButton.Self would not work? Thank you!

//Is still not working for me, Not sure sure what I'm doing wrong

class Button { var width: Double var height: Double

init(width:Double, height:Double){ self.width = width self.height = height } class RoundButton: Button { var cornerRadius = 5.0 } var rounded = RoundButton(width: 10.0, height: 10.0)

}