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

kevin nadjarian
kevin nadjarian
1,498 Points

Return function and string

Not sure I got it

Tyler Simko
Tyler Simko
5,610 Points

Hey Kevin,

Hopefully I can help - what's your question?

kevin nadjarian
kevin nadjarian
1,498 Points

Hi Tayler, thanks,

I just cannot get the code correct with a string :

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

println("hello (greeting("tom"))")

the result is "hello (Function)" and not hello tom

3 Answers

kevin nadjarian
kevin nadjarian
1,498 Points

Yes that what I did too sorry but I cannot get still have an issue

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

println("hello (greeting("tom"))")

I also try with

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

println("hello (greeting(tom))")

And also try

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

println("hello (greeting(tom))")

Can some one give me the correct answer for this exercices "Function return type" in Swift Functions and Optionals courses

Thank you

Jeremy Hayden
Jeremy Hayden
1,740 Points

You forgot the / for string interpolation. "Hello /(greeting...

kevin nadjarian
kevin nadjarian
1,498 Points

The solution was like this, finded my answer.

func greeting(#personName: String) -> String { let greetings = "Hello, " + personName + "!" return greetings }

println(greeting(personName: "Kevin"))