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

John Stephanites
John Stephanites
2,007 Points

Function Return Types

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

This is what I have and I just can't figure it out so please help!

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

3 Answers

John Stephanites
John Stephanites
2,007 Points

This is what ended up working for me.

fund greeting(personName: String) -> String { let greeting = "Hello, " + personName return greeting }

Jason Safdie
Jason Safdie
3,461 Points

First, tell the function to return a type String. Next, replace the println statement with a return statement and drop the parentheses. Finally, hop outside the function and call it while passing the String "Tom" inside. Hope that clears it up.

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