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

How do I return a "Hello" right next to (person)?

I don't understand how to complete this challenge. I'm supposed to return a variable next to a constant but i can't seem to use string interpolation correctly.

The answer is not: return ("Hello (person)") (NOTE: the editor doesn't show the backslash before (person))

Please help

returns.swift
func greeting(person: String) {
    return greeting
}

3 Answers

Roberto Alicata
PLUS
Roberto Alicata
Courses Plus Student 39,959 Points

First you have to define the return type adding "-> String" after the parameters of the function

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

then you need to replace the println function with a return statement

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

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

Thank you Wes and Roberto. I forgot about '-> String'