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

Does anyone have a solution to the Object Oriented Swift 2.0 code challenge structs.swift? I can't figure this one out.

I get no errors in playground but it still tells me I am wrong

Would you mind posting the code that you currently have? That might help identify the problem. :)

struct Person { let firstName: String let lastName: String func getFullName(firstName: String, lastName: String) -> String { let fullName = firstName + " " + lastName return fullName }

}

2 Answers

Hi Joe,

Here's the solution I used. In this case, you don't need the instance method (getFullName) to do anything other than concatenate the local variables firstName and lastName. So no parameters are needed on the instance method.

struct Person {
    let firstName: String
    let lastName: String

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

//Then you can create an instance e.g.:
let somePerson = Person(firstName: "Joe", lastName: "Bloggs")
somePerson.getFullName() // <-- returns "Joe Bloggs"

Thanks