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

Mark Robinson
Mark Robinson
1,736 Points

Swift Methods and Struct challenge

I am having trouble setting up the instance and function in this Swift struct challenge to return the first and last name. Not sure what code is missing (perhaps a loop?)

thanks

structs.swift
struct Person {
    let firstName: String
    let lastName: String

    func getFullName(names: String)->String
    {
       let nameOfPerson = firstName + lastName
        return nameOfPerson
    }


let getFullName = String(firstName: , lastName: )

1 Answer

Michael Hulet
Michael Hulet
47,913 Points

The challenge asks you to account for a space in between the names, which you're not doing. This should work:

struct Person {
    let firstName: String
    let lastName: String

    func getFullName() -> String{
        //Notice the space in the middle
        return firstName + " " + lastName
    }
}
Mark Robinson
Mark Robinson
1,736 Points

The response from the Treehouse editor keeps saying : "Make sure you're adding an instance method named getFullName() to the struct definition."

Any tips on syntax?