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 Complex Data Structures Adding Instance Methods

I need help solving this code challenge.

I have tried this numerous ways, and this seems to work in my playground but does not work in the code challenge. Any help would be appreciated!

structs.swift
struct Person {
    let firstName: String
    let lastName: String
    func getFullName() -> String{
    return "\(firstName) \(lastName)"

    }
}
let aPerson = Person(firstName: "Alex", lastName: "Nelsen")
aPerson.getFullName()

2 Answers

Hey Alex Nelsen,

You need to assign the value you are returning from your call of getFullName to a constant called fullName.

struct Person {
    let firstName: String
    let lastName: String

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

    }
}

let aPerson = Person(firstName: "Alex", lastName: "Nelsen")
let fullName = aPerson.getFullName()

Good Luck

Could someone explain why this needs to be done to complete the code challenge but not in playground?

That worked great. I appreciate all your help today!

No problem :)