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 trialMohamed Behary
5,190 PointsI need your help
Could anyone help me to find a solution to this challenge ?
Challenge Task 1 of 1
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?
class Button {
var width: Double
var height: Double
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
}
}
4 Answers
Chokdee Srisuk
19,384 Pointsclass RoundButton: Button {
var cornerRadius: Double = 5.0
init(width:Double,height:Double,cornerRadius:Double){
self.cornerRadius = cornerRadius
super.init(width: width, height: height)
}
}
Mohamed Behary
5,190 Pointsthank you but could you write the correct answer again ?
Mohamed Behary
5,190 PointsThank you
Dave Pinchoff
4,440 PointsI don't know if this is an appropriate space to ask this question, but it tags onto what has already been said, so thanks for the help in advance:
Why is it that in the super.init call, we write (width: width, height: height)?
I was expecting to write (width: Double, height: Double).
Kenneth Giorno
4,043 Pointsbecause we've already passed in the width and height variables as doubles in the start of the init method. we then re-use these values in the super.init call
Dave Pinchoff
4,440 PointsKenneth -
ahh... thanks - i see that now.
happy coding!
Chokdee Srisuk
19,384 PointsChokdee Srisuk
19,384 PointsIn designated initializer of class RoundButton, you need to add designated of super class to it.
super.init(width: width, height: height)
So class RoundButton would be
class RoundButton: Button { var cornerRadius: Double = 5.0
init(width:Double,height:Double,cornerRadius:Double){ self.cornerRadius = cornerRadius super.init(width: width, height: height) }
}