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 trialTywan Claxton
8,397 PointsIos Overriding initializer
I keep receiving a compiler error stating, initializer does not override a designated initializer from its superclass
enum Condition {
case poor
case fair
case excellent
}
class Shoe {
var color: Condition
var laces: Condition
init(color: Condition, laces: Condition) {
self.color = color
self.laces = laces
}
}
class Nike: Shoe {
var texture: Condition
var sole: Condition
override init(color: Condition, laces: Condition, texture: Condition, sole: Condition) {
self.texture = texture
self.sole = sole
super.init(color: color, laces: laces, texture: texture, sole: sole)
}
}
1 Answer
James Mulholland
Full Stack JavaScript Techdegree Student 20,944 PointsI think I've worked out what's going on here.
Essentially, what I think is happening is that the override keyword is not needed as the init method in the subclass (Nike) is a different init() method to the one in the superclass (Shoe) as they take different parameters. Therefore, you need to get rid of the override in the Nike class.
There's a second problem too. When you call super.init() you're calling the init() method from Shoe. This init() method doesn't have the texture or sole parameters so you need to get rid of those. They'll be assigned fine by self.texture and self.sole = sole.
Tywan Claxton
8,397 PointsTywan Claxton
8,397 PointsThank you so much