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 trialJarrett Young
12,635 PointsCOMPLETELY lost on Tuples in Swift
This section on Tuples has gone way over my head. I still don't understand how they're used. I guess for now I'm just going to have to skip this code challenge because I have NO idea what it's asking me to do or why I'm doing it.
func greeting(person: String) -> String {
let language = "English"
let greeting = "Hello \(person)"
return greeting
}
1 Answer
kjvswift93
13,515 PointsA tuple is essentially a group of values that can be treated as a single entity. Tuples are useful for storing related or temporary values in a single container.
In the first part of the challenge where it asks you to modify the greeting function to return 'greeting' and 'language' as a tuple, the updated code would be this:
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}