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

Overriding Methods Swift 2.0. Code breaks "Check Work" after "Preview"

Course: Object-Oriented Swift - Class Inheritance - Challenge: Overriding Methods

I thought it would be quite easy if I just add a new constant named title and return that along with the lastName. So it looked like this.

class Doctor: Person{
    var title: String

    init(title: String, firstName: String, lastName: String){
        self.title = title
        super.init(firstName: firstName, lastName: lastName)
    }

    override func getFullName() -> String {
        return "\(title) \(lastName)"
    }
}

in the playground everything was fine, but when I pasted it in I only got the "Bummer!". If I was restless and pushed the button too often I even crashed the thing.

Here is a screenshot of the "Bummer"

Only possibility was to "dumb it down" and it worked.

class Doctor: Person{
    override init(firstName: String, lastName: String){
        super.init(firstName: firstName, lastName: lastName)
    }

    override func getFullName() -> String {
        return "Dr. \(lastName)"
    }
}

My question is now, if there was a mistake or any other person with the same problem.