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
Abdurahman Sharif
1,205 Pointssilly question from a beginner trying to understand tuples.
hey guys and gals. im not really getting or understanding tuples.. what are they? and what do we really need to know them for, what will they be used for if i want to make an app or something?.
im sorry if this is a really broad question. but im having a hard time wrapping my head around them and why i need to know them, and i know that they have some importance. but please if someone can. simplify it for me..
thanks
1 Answer
kjvswift93
13,515 PointsThese two snippets of code here are great for understanding the difference between a function that only returns a single value and one that returns a tuple.
func greeting(person: String) -> String {
let language = "English"
let greeting = "Hello \(person)"
return greeting
}
ā
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
faranaway
Courses Plus Student 13,885 Pointsfaranaway
Courses Plus Student 13,885 PointsHi Abdurahman Sharif!
I think Amit said it best during his introduction to tuples. Tuples can be used as a standalone or as a return type to a function.
Generally, tuples are used whenever you want to return multiple results from a function.