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 Convenience Initializers

Is it wrong way ?

Why we should use convenience init. to add default values , where we can do in such way

My way:

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

init(title: String = "Clothing Item", price: Double = 99, designer: String = "Calvin Klein") {
    self.designer = designer
    super.init(title: title, price: price)
}

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

In video:

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)
}

convenience init (title: String) {
    self.init(title: title, price: 99, designer: "Calvin Klein")
}

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

So we can have same result without convenience init. ?

Thank you