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

Kevin Walker
Kevin Walker
2,354 Points

Having trouble returning strings

I am having trouble with the 1st part of the challenge on Structs. I have setup the function and have set the function for return types of two Strings with names firstName and lastName. Inside the body of the function, I have set the function to return those variables. The challenge is telling me to make sure my function has no parameters (which it does not) and that it is returning a String. I am assuming I am not supposed to do anything inside the function, even though the challenge asks for a complete full name. Here is where I currently am:

struct Person {

let firstname: String
let lastname: String

func getFullName() -> (firstname: String, lastname: String) {

    return (firstname, lastname)

}

}

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

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,624 Points

Hey Kevin,

You're kind of on the right track. First off, your return statement is a bit off. You can't include variables/constants in the return type... only the type.

Second, your return statement is in the correct place, but you need to return a concatenated string that includes a space between the first name and last name.

Below is the correct code. Have a look, and I hope it makes sense. :)

struct Person {
    let firstName: String
    let lastName: String

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

Keep Coding! :dizzy:

Kevin Walker
Kevin Walker
2,354 Points

Thanks Jason! Another question: In previous videos, Pasan talks about setting up your return in the function declaration with names. Is that not appropriate here?

Jason Anders
Jason Anders
Treehouse Moderator 145,624 Points

Hi Kevin.

I watched the 2 videos prior to the quiz and was not able to find what you are referring to. In both videos, the return type of the function he has is a Point (or more specifically an Array of Points).

If you could provide a link to the video you're referencing and a time-stamp, I'll have look. :)