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

why is my code refusing to accept the 'super.init' call???

class Product { var title: String var price: Double

init(tit: String, pri: Double) { self.title = tit self.price = pri }

func discountedPrice(percentage: Double) -> Double { return price - (price * percentage / 100) } }

enum Size { case Small, Medium, Large init() { self = .Small } }

class Clothing: Product { var size = Size()

let designer: String init(tit: String, pri: Double, designer: String) { self.designer = designer super.init(tit: title, pri: price) }

this is my code. but an error is coming up on the last line ("super.init(tit: title, pri: price)") saying "Use of property 'title' in base object before super.init initialises it".

I have followed every step taken by Amit in the video and can't work it out because I have initialised it in my base class.

Any help would be much appreciated.

I've just checked your code and the problem is that in the initializer of your base class you are not passing in the proper variables to the superclasses' constructor:

    init(tit: String, pri: Double, designer: String) {
        self.designer = designer
        // Pass the tit and pri values to the super classes constructor
        super.init(tit: tit, pri: pri)
    }

Hence the error on why the title property was not being set in the super class.