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

What am i doing wrong in the task?

Unclear Task description. The code i write returns "Hello Tom" in result variable within a Xcode playground. What am i doing wrong in the task?

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

}

var result = greeting("Tom").1

2 Answers

Martin Wildfeuer
PLUS
Martin Wildfeuer
Courses Plus Student 11,071 Points

Create a variable named result and assign it the tuple returned from function greeting. (Note: pass the string "Tom" to the greeting function.)

In this task, don't assign a specific value of the tuple to result, but rather the tuple itself.

var result = greeting("Tom")

One more thing :) To pass this task, the order of the returned tuple has to be (1) greeting and then (2) language. Although you will pass the first task, code check requires this specific order to pass the second.

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

}

var result = greeting("Tom")

Hope that helps :)

Ah ok. I had it without the .1 but it told me the value of result was wrong. So I forgot to change the order of the tuple content.

Thanks for the hint.