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

Gokul Nishanth S
Gokul Nishanth S
1,349 Points

Make sure your function does not take any parameters and returns a String

struct Person 
{
    let firstName: String
    let lastName: String

    func fullName() -> [String] // remove square brackets
    {
      return ["\(firstName) \(lastName)"] // remove square brackets
    }
}

let name = Person(firstName: "Gokul", lastName: "Nishanth")
name.fullname()

1 Answer

Hi there,

I don't think you need the square brackets around the returned data type or the returned value itself. The rest looks OK.

Try:

struct Person {
    let firstName: String
    let lastName: String

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

I hope that helps,

Steve.

I added some comments in your code to illustrate my point.

Steve.

Gokul Nishanth S
Gokul Nishanth S
1,349 Points

Thank You.

But my code works fine in Xcode Playground. What maybe the problem here.

No problem! :+1: :smile: