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

dexter foo
dexter foo
8,233 Points

Hi I don't understand how the code i wrote is not as what the question is asking

Hi, the question asked for me to assign a variable result to the return tuple from the function greeting.

why is this wrong?

var result = greeting(person: "Tom")

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

    return (greeting, language) 
}

var result = greeting(person: "Tom")

2 Answers

Person is the name of the parameter belonging to the greeting function definition, and is of type string. Meaning you only need to do this.

var result = greeting("Tom")

Since you are not actually creating a new function with a parameter name, but simply assigning a string to a new variable, it doesn't make sense to assign a function with the parameter name "person" of type "Tom" (which is not a data type!) to a new variable.

Brian Patterson
Brian Patterson
19,588 Points

So why does it not work? var result = greeting ("Tom")