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

Jon Schenck
Jon Schenck
2,028 Points

help with tuples please

Cant get this to work. Please help

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

    return (greeting, language)
}

var result = greeting("Tom", "English")

println(language)

2 Answers

Fuad Adetoro2
seal-mask
.a{fill-rule:evenodd;}techdegree
Fuad Adetoro2
iOS Development Techdegree Student 2,870 Points

Remember that the only parameter you're calling is "Person" so when you create your variable you don't need to pass the language!

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)
Chengyu Deng
Chengyu Deng
7,879 Points

If you want to call the greeting function, you only need to enter the parameter which in this case the parameter is person.

The code should be like:

my screenshot/ image link

Then you can print the language out by println(result.language)