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 Swift Functions and Optionals Functions Function Return Types

Donda Kai
Donda Kai
754 Points

How do i solve this?

hi

returns.swift
func greeting(person: String) {
    return ("Hello \(person)")
}

4 Answers

Hi there,

To make the method return something, you need to add a -> to the declaration. That also states what is being returned, so that's -> String in this case.

Then you need to use the return keyword to make that happen inside the code:

func greeting(person: String) -> String {
    return "Hello \(person)"
}

Hope that makes sense.

Steve.

Donda Kai
Donda Kai
754 Points

That didn't help at all! It's just saying bummer

Pasan Premaratne
Pasan Premaratne
Treehouse Teacher

If you're returning ("Hello (person)"), i.e, you're wrapping the string in parentheses, then you're returning a tuple containing a String, and not a String. Remove the parentheses to return a String.

Works fine for me - have you copied the code exactly? I've just redone the challenge a number of times to check. If you could paste me a screenshot of that code failing the challenge that would be great - there may be something amiss with the system.

Steve.

func greeting(person: String) -> String {
    return "Hello \(person)"
}