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

Zachary Goforth
Zachary Goforth
748 Points

How do I pass Challenge Task 3 on Tuples?

I put in... println(result.language)

and received...

You printed "Hello Tom". It should have printed "English"

How do I print "English?"

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

    return (greeting, language) 
}

var result = greeting("Tom") 

println(result.language) 

2 Answers

Jon Schenck
Jon Schenck
2,028 Points

Just switch greeting and language on your return value.

return (language, greeting)

Enrique Munguía
Enrique Munguía
14,311 Points

Your code is almost right, the problem is when you return the tuple with items in incorrect order. The method signature says the tuple contains two elements language and greeting in that exact order, but the return statement constructs a tuple with greeting and language.

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

    return (language, greeting) 
}

var result = greeting("Tom") 

println(result.language) 

The solution is easy, just create the tuple in right order.