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

Still getting an error:

struct Person { let firstName: String let lastName: String

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

}

made corrections but still complaining about not declaring a getFullName method. Works fine in the playground.

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

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

3 Answers

Apparently they want you to use String interpolation rather than concatenation:

    func getFullName() -> String {
      return "\(firstName) \(lastName)"
    }
}
Travis McCormick
Travis McCormick
2,313 Points

Hey Ben!

In the challenge description, it states "Declare a method named getFullName() that returns a string containing the person’s full name." So in this case, you literally have to return a string.

return "\(firstName) \(lastName)"

Your code it right, so don't feel discouraged. A lot of challenges have been very frustrating for me and I've realized that sometimes you have to read the challenge description very slowly to make sure you're not missing anything!

I hope this is helpful!

Actually, isn't it the case that Ben is returning a String:

return firstName + " " + lastName

It's just that he's creating the String using String concatenation, while the editor wants him to use String interpolation.

:)

Travis McCormick
Travis McCormick
2,313 Points

Hmm.. Now that I look at it, firstName and lastName are both of type String so the result will still be a string.

I remember having the same issue on this challenge, and when I finally tried changing it to the other format, the editor accepted it. I guess I just made the assumption.

Thanks for the clarification!