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 Inheritance and Initializers

Aaron Creasey
Aaron Creasey
1,707 Points

Getting Error: Extra argument 'title' in call. Near end of video

On the last line of my code I am getting the error: Extra argument 'title' in call. I have inherited the supers init and added the designer into it as well but it does not want to work out.

when I type in : var t-shirt = Clothing it auto completed to (designer: String)

Here is my code:

class Clothing: Product { var size = Size() let designer: String

init (designer: String) {
    self.designer = designer
    super.init(title: title, price: price)
}

override func discountedPrice(_ percentage: Double = 10.0) -> Double {
    return super.discountedPrice(percentage)
}

}

var tshirt = Clothing(title: "Vintage", price: 400.00, designer: "Prada")

1 Answer

So it appears there is a change in the init when a super.init is used change the init to include the parameters of the class

class Clothing: Product{ var size = Size() let designer: String

init (title: String, price: Double, designer: String) {
    self.designer = designer
    super.init(title: title, price: price)
}
override func discountedPrice(_ percentage: Double = 10.0) -> Double {
    return super.discountedPrice(percentage)
}

}

var tshirt = Clothing(title: "Vintage", price: 49.99, designer: "Prada")