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

AR Ehsan
AR Ehsan
7,912 Points

I am stuck! Can someone help me! I will mark as best answer!

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")
            println("\(language)")

12 Answers

AR Ehsan
AR Ehsan
7,912 Points

No! You are helping me with another code challenge! That's the problem!

Try only below

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

    return (greeting, language)
}

When you click on tuples.swift it takes you directly to the code challenge.

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

    return (greeting, language)
}
AR Ehsan
AR Ehsan
7,912 Points

Not tuples.swift It is the first code challenge in the last stage of swift functions and optionals.

Hello, greeting function is returning a tuple. Since it is not named tuple you can do this:

let (greeting, language) = greeting("Tom")

then you can do

println("\(language)")

or

println("\(greeting)")
AR Ehsan
AR Ehsan
7,912 Points

Can you help me with task 2!

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

    return (greeting, language)
}

let result = greeting("Tom")

Please review updated code.

Try below: You will need to set named tuple as return value then you can use it as result.language

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

    return (greeting, language)
}

var result = greeting("Tom")

For setp2 you should not create var result = greeting("Tom") part i guess. Just remove that line

AR Ehsan
AR Ehsan
7,912 Points

That is all wrong!

AR Ehsan
AR Ehsan
7,912 Points

It's search.swift

AR Ehsan
AR Ehsan
7,912 Points

Oh I just forgot! I past that code challenge!

AR Ehsan
AR Ehsan
7,912 Points

I don't understand you! Can you paste some code!

AR Ehsan
AR Ehsan
7,912 Points

I think you guys are helping me with something else