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

Rohan Prashanth
Rohan Prashanth
1,205 Points

Can someone help me figure out why my code for the code challenge isn't working?

The hint given is that I should make sure I am adding the instance in the struct definition

struct Person {
    let firstName: String
    let lastName: String

    init(firstName: String lastName:: String) {
        self.firstName = firstName
        self.lastName = lastName

        func fullName(firstName: String, lastName: String) -> Person  {
                var result = Person(firstName, lastName)
  return result

1 Answer

Bruce Röttgers
Bruce Röttgers
18,211 Points


a struct doesn't need a custom initializer. Also the initializer definition has 2 errors:

  1. Between first name and last name parameters needs to be a comma.
  2. You used two colons behind the lastName parameter

the right way it would look like this

init(firstName: String, lastName: String) {

Next error, you are returning the result outside of the function.

Next error: The function should return a String and not an instance of Person

Next error: The string should be the first name + a space + the last name

Hope that helps, please don't forget to select this as a best answer if it solved your problem.