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 2.0 Class Inheritance Overriding Methods

Hi, can somebody help me solve a problem and feels like every time I am getting closer something else pop up lol. Please

class Person { let firstName: String let lastName: String

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

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

}

// Enter your code below

class Doctor: Person {

override func getFullName() -> String {
    return getFullName()
}

} let someDoctor = Doctor(firstName: "Sam", lastName: "Smith")

1 Answer

Hi Tiemoko! Right now, your function definition is a little strange. You're calling getFullName() inside of override definition of getFullName() -- but what you want to do is give it a new return definition, where you're telling it to return "Dr. LastName." You should have something like...

class Doctor : Person { override func getFullName() -> String { return "the string you actually want to see" } }

... where, of course, "the string you actually want to see" is... well, what you want to see. Hope that helps!

(EDIT: Was missing the function definition in the first pass!)

Hi Tatiana! I perfectly see the problem now and resolved it. Thanks for your help!