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

Im trying to pass in a String "Tom" To have a return String say "Hello Tom"

I know i almost got it but i cant seem to figure out that 1 step im missing.

Thanks,

returns.swift
func greeting(person: String) -> String {
    return "Hello" + person
}
greeting ("Tom")

1 Answer

Greg Kaleka
Greg Kaleka
39,021 Points

Hey Marco,

You've got it, you're just not doing anything with the returned value. You want to either print it, or store it in a variable, or both.

func greeting(person: String) -> String {
    return "Hello " + person    // I added a space here
}
var result = greeting("Tom")   // I removed the space in the function call here
println(result)    // this will output "Hello Tom"

Hey Greg,

I'm sorry but i don't get what you mean by add a space on my return, i did it and its not working.

Greg Kaleka
Greg Kaleka
39,021 Points

Hey Marco - I edited my code to add the space in myself. Also, you have an extra space in your function call. I think that might cause a problem.

Thanks Greg, finally got it.