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 trialPhilip Charlemagne
5,813 PointsSwift Code Challenge: Overriding incrementBy func
I am trying to override the "incrementBy func" so that I can implement it in the roundButton class and add the correct point parameter of 7.0.
This is how I'm implement the override in the roundButton class
class RoundButton: Button { var cornerRadius: Double = 5.0 override func incrementBy(points: Double = 7.0)-> Double{
} }
Should I be looking at the incrementBy that needs to be used in the roundButton class as a method signature eve if it doesn't include the keyword "return?"
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
}
2 Answers
Michael Liendo
15,326 PointsSince the original incrementBy
function doesn't have a return type then you wouldn't need to put one in the new one. Instead, simply take that out, put an underscore _
followed by a space, and then write points: Double = 7.0
as your parameter.
Hope this helps, you were super close to getting it! Keep up the good work!
Philip Charlemagne
5,813 PointsAwesome that worked! Thank you Michael!