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 trialMOHAMMED ALYOUSEF
909 PointsI don't know how to return string
could you please help
func greeting(person: String) {
println("Hello \(person)")
}
1 Answer
Alvin Abia
Courses Plus Student 23,034 PointsHey Mohammed, when you want to add a return type to your function you add a '->' followed by whatever return type you need. This would look like this:
func greeting(person:String) -> String
When you declare a return type within your function, it is important that you return a value of that specific type within your statement. This is denoted by typing 'return' followed by the value that you want to return. If you wanted to return a string, you would denote so like this:
return "Hello \(person)"
I hope this helps, let me know if you have anymore questions. With a little practice, I know this will become second nature for you =)