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

Wei Luo
Wei Luo
1,372 Points

Task1

I would like to know why my code didn't work?

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

i think you forgot the return type something like

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

2 Answers

You are still printing the greeting...but the challange said you should use the return statement

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

Some information https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html

Wei Luo
Wei Luo
1,372 Points

What if I chant it to return person } println("Hello (greeting(person))")

Uhm i dont really get that question...I already posted the right code. The problem is, that you DONT have to PRINT anything.

also you need to add the "-> String" which is the return-type of your function.

return is not the same as println Compare my code and yours and you should see the differences. Also take a look at my link it should help you

Wei Luo
Wei Luo
1,372 Points

Thanks a lot Tobias Krause!