Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Object-Oriented Swift Complex Data Structures Adding Instance Methods

Ingunn Augdal Fløvig
Ingunn Augdal Fløvig
1,507 Points

Using instance method to combine first and last name into full name for a structure "Person"

I get an error saying "make sure you're adding an instance method to your struct definition", but I'm not quite sure what I should change to accomplish that.

struct Person {
    let firstName: String
    let lastName: String

    func fullName(firstName: String, lastName: String) -> [Person] {
    var results = [Person]()

    let firstNameOfPerson = firstName
    let lastNameOfPerson = lastName

    let results = ["\(firstNameOfPerson) \(lastNameOfPerson)"]

    return results

2 Answers

Magnus Hållberg
Magnus Hållberg
17,232 Points

I think you have been thinking to much on this and made it over complicated for your self. The challenge say to create a method named fullName() that return a string. It doesn't say you need any inputs so the simple way of doing it is to make a string interpolation from the two properties in the struct and return it.

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