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

William Bergstein
William Bergstein
2,078 Points

What is wrong with my Code?

I have tried using return(greeting,language) and I have tried using the strings instead of the constants because I told the function to return two strings. I even created a variable that consisted of the conactation of greeting and language and then tried to return that. I dont understand what I am doing wrong.

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

    return (greeting,Language)
}

I think you made a typo? You capitalized language or vise versa?

func greeting(person: String) -> (String,String) {
    let language = "English"
    let greeting = "Hello \(person)"
    return (greeting,language)
}
William Bergstein
William Bergstein
2,078 Points

No its not a capitalization thing. I just checked.

2 Answers

Dave Berning
Dave Berning
17,365 Points

The typo wasn't the major issue. The major issue was that you're declaring the return value to be (String,String) when it should have the constant name before each one.

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

    return (language, greeting)
}

var output = greeting("Dave")
println(output) // just to see output for testing purposes

I realized this later. I forgot to come back to update my answer. Uboat to you.

I think you made a typo? You capitalized language or vise versa?

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