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

Khalid Seirafi
PLUS
Khalid Seirafi
Courses Plus Student 1,546 Points

Assigning the return value (a tuple) of a function to a variable.

I'm not quite sure how to do this.

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

    return x
}

var result = greeting("Tom")

2 Answers

Sam Matrouh
Sam Matrouh
14,694 Points

You're almost there. Instead of returning variable x, just return the Tuple. Might also have something to do with the fact that you don't have the right placement for arguments in your function. According to the instructions it should be greeting,language.

Although your code runs fine in Xcode, Treehouse doesn't seem to like it. Below is the complete code.

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

    return (greeting, language)
}

var result = greeting("Tom")
println(result.language)

Hope this helps :-)