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 trialKarthikeya Nadendla
9,747 PointsNeed help to fix the code
Once again we are working with the RoundButton class and started to add a designated initializer to it. However, there's something wrong with it. Can you figure out how to fix it and make it work?
I have added the super.init in the init but still it says error and I dont understand why. Please help me on this
class Button {
var width: Double
var height: Double
super.init (width:Double, height:Double){
self.width = width
self.height = height
}
func scaleBy(points: Double){
width += points
height += points
}
}
class RoundButton: Button {
var cornerRadius: Double = 5.0
init(width:Double,height:Double,cornerRadius:Double){
self.cornerRadius = cornerRadius
super.init(width: width, height: height)
}
}
1 Answer
Richard Lu
20,185 PointsHi Karthikeya,
Your code is so close to being perfect. The problem is that when you define your designated initializer in your Button class, you call super.init(....). When you call super.init in your RoundButton, you're calling the parent classes initializer which is Button.
class RoundButton: Button { /* parent class is Button aka the super */ }
In Button, there is no super class.
class RoundButton { }
If you change this line in your Button class, the error will go away.
super.init (width:Double, height:Double)
change it to
init (width:Double, height:Double)
Happy coding! :)
Karthikeya Nadendla
9,747 PointsKarthikeya Nadendla
9,747 PointsThank you I go it !