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

silly 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

Hi 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.

1 Answer

These 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)
}