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

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!