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

I'm able to return a tuple and in Xcode I can see it return the correct value. But I'm unable to go to the next step.

my tuple constant is greetingLanguage. it contains two strings, and even though I can return the tuple it still will not let me continue to the next step. Perhaps it is just my mistake. Thanks for your time!

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

1 Answer

Task 1: Modify the greeting function to return both the greeting and language as a tuple. Remember to return inside the function (the "return") and in the declaration (after the "->")

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

    return (greeting, language)
}

Task 2: Create a variable named result and assign it to greeting. Pass the string "Tom" to greeting.

var result = greeting("Tom")

Task 3: Use the print function, print the value of the language element from the result tuple. This is just using dot notation to access the value.

println(result.language)

Thanks! I was getting my types switched around.