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

David Galindo
PLUS
David Galindo
Courses Plus Student 2,294 Points

Function Return Types

For this challenge we are ask to modify the current function with a return type and yo use the println, the output should say "Hello Tom". the part that I am having trouble is when call the function in the println. I thought that the println statement should look like this.

println("Hello (greeting("Tom"))") but this does not compile why is that ??

David Lu
David Lu
17,493 Points

You can find a similar question posted in this forum

https://teamtreehouse.com/forum/using-the-return-type

4 Answers

Andres Oliva
Andres Oliva
7,810 Points

I don't believe that you can use string interpolation that way.

You can use something like this:

println("Hello" + greeting("Tom"))

or this:

let greeting = greeting("Tom")
println("Hello \(greeting)")

but that line of code you're writing doesn't make much sense to me.

David Galindo
PLUS
David Galindo
Courses Plus Student 2,294 Points

why is this wrong ???

func greeting (person : String) ->String{

    return person


}



println("Hello \(greeting ("Tom"))")
David Lu
David Lu
17,493 Points

What Andrew says...

And also, Swift (or many other languages) don't like double quotation marks inside a double quotation marks.