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

Aditya Sanghi
Aditya Sanghi
8,044 Points

func greeting(person: String) -> String { let language = "English" let greeting = "Hello \(person)" return greeting

Currently our greeting function only returns a single value. Modify it to return both the greeting and the language as a tuple. Make sure to name each item in the tuple: greeting and language. We will print them out in the next task

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

    return greeting
}
Anjali Pasupathy
Anjali Pasupathy
28,883 Points

Where are you having trouble? Is there an aspect of the question you don't understand? Did you write code that didn't pass? If so, could you state what aspect of the question you didn't understand, or post your code?

1 Answer

Hi Aditya. It seems that you have an incomplete question there. I presume you were unable to proceed with the challenge

The challenge is asking you to return a tuple of the two variables inside the definition of the function. To do so, you have to modify the return type in the function to the tuple to a type of (String, String), the same types as the two return values in the tuple (greeting is a String and language is also a String)

To make a tuple, you simply have to return a tuple of greeting and language variable like this: (greeting, language)

The full problem statement from viewing the challenge says: "Currently our greeting function only returns a single value. Modify it to return both the greeting and the language as a tuple. Make sure to name each item in the tuple: greeting and language. We will print them out in the next task."

That means the return type needs to look like this: (greeting: String, language: String)

This program should pass the challenge:

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

    return (greeting, language)
}

Let me know if you have further doubts. Good luck with Swift!