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

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.