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

This code is working in the Playground, but not in the challenge

The error says I'm using secondName instead of lastName

Steven Deutsch
Steven Deutsch
21,046 Points

Hey Erin Krentz,

Can you post your code so that I can take a look? Maybe I can help, thanks.

struct Person {
    let firstName: String
    let lastName: String

    func getFullName (firstName: String, lastName: String) -> String {
        return "\(firstName) \(lastName)"
    }
}
Jake Adams
Jake Adams
1,608 Points

Your solution is valid and a common practice, but that's not the pattern the lesson parser is looking for. See my answer below. Hope it helps!

How can I skip the challenge?

Jake Adams
Jake Adams
1,608 Points

Were you able to get through the challenge with my answer below?

1 Answer

Jake Adams
Jake Adams
1,608 Points

You need to use the instance properties of the Person struct instead of passing arguments to the function.

struct Person { 
  let firstName: String 
  let lastName: String

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

-edit- replace original answer now that I saw the underlying issue

This still doesn't work. Is there any way to skip the challenge?

struct Person {
    let firstName: String
    let lastName: String

    func getFullName(firstName: String, lastName: String) -> String {
        return firstName + " " + lastName
    }
}
Jake Adams
Jake Adams
1,608 Points

ah, I see the issue now. You are passing in arguments to the function when you should be using the instance properties. I totally missed that originally, so your original solution will work as long as you remove the function arguments.