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 Swift Functions and Optionals Parameters and Tuples Tuples

Struggling to return two values in a tuple. Not sure where my mistake is. I may be completely missing the mark here.

I'm looking to return two values through greeting as an tuple and i'm getting a ton of compiler errors. Any idea how to fix? I've been struggling with Tuples for some reason. Perfectly understand the concept, just the syntax is catching me up.

tuples.swift
func greeting(person: String) -> (#greeting: String, #language: String) {
    let language = "English"
    let greeting = ("Hello \(person)", language)

    return greeting
}

1 Answer

Chase Marchione
Chase Marchione
155,055 Points

Hi Tyler,

1) Hashtags can be used if a function's label and parameter names are the same, so if we were to hashtag anything, it would be before the parameter on the left side of the return arrow.

func greeting(person: String) -> (greeting: String, language: String) {

2) Let's update the return statement to include both greeting and language. Since we can't have two return statements, we'll have one return statement return both values.

    return (greeting, language)

Hope this helps!

Huge help CJ! Thanks so much! Much clearer now I really appreciate it.