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 trialJosh Smith
1,049 PointsReturning Multiple Values in a Tuple
Stuck once again... I look at this question and I don't even know where to start?
func greeting(person: String) -> String {
let language = "English"
let greeting = "Hello \(person)"
return greeting
}
1 Answer
Enrique Munguía
14,311 PointsA tuple is specified with parenthesis (), if you are using a tuple as a return type you can write
func myFunc() -> (String, String) {
return ("hello", "world")
}
In this example, myFunc returns a tuple consisting of two strings, remember that tuples can have multiple values and even diferent types for each value, the return statement creates a tuple with the strings "hello" and "world", but you can replace those strings with variables as in your example.
Josh Smith
1,049 PointsJosh Smith
1,049 PointsThanks Enrique!