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

I am totally stumped on this one. I cant replicate the same thing with a string.

It says modify the definition to be a string

clearly you add -> string after the () in greeting, but when it asks me what to return, i am lost. I think I need to return (person) since that is what value we are passing through as a string, but it says I am wrong.

returns.swift
func greeting(person: String) -> String {
    Return (person)
}

1 Answer

Hi Casey, your almost there.

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

first of all, return is lowercase in Swift. Second of all, it is asking you to return a string that will be formatted like "Hello name". To do this we will interpolate the person variable declared as a parameter and pass that to our string. That way, no matter what name we input, we will get "Hello (name inputted)". I hope this helps!

Thank you, chris. That cleared things up. I failed to output the return value as a string, which was my mistake in this exercise. Thank you for your help.