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

Roderick Royce
Roderick Royce
1,236 Points

How do I properly set up a String Function? Team Tree House has taught me how to set up an Int but not a String.

How do I successfully insert Tom into the equation and return person to print "Hello Tom".

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

2 Answers

Brent Petit
Brent Petit
7,860 Points

If you intend for Tom to be the input to the function then I believe you are looking for something like this. Note I've added a caller to show Tom as the input.

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

    println(greeting("Tom"))

greeting takes a String and returns a String.

Roderick Royce
Roderick Royce
1,236 Points

Thank you Bret Petit. Your response was successful and helpful. I hope I didn't sound too negative in my question. Take care.