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

Daniel Morgenstein
Daniel Morgenstein
744 Points

I can't figure out this question

I believe I am executing exactly what the question is asking, how frustrating !

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

    return (greeting, language)
}
var result = greeting(language: "Tom")

1 Answer

Tommy Choe
Tommy Choe
38,156 Points

Hey Daniel, you did a good job writing the return type and returning a tuple with two values. The problems are regarding the parameter type and the argument passed in to the function.

For the parameter name "person", you want to specify the type of the value that it can accept. In this case that would be type String.

// So change it from:
func greeting(person: "Tom") -> (greeting: String, language: String) {

// to:
func greeting(person: String) -> (greeting: String, language: String) {

Next, you're trying to pass in an argument for the constant "language" instead of the parameter "person". All you need to do to rectify the problem is to take out the external parameter name "language" from the function call.

// Change from:
var result = greeting(language: "Tom")

// to:
var result = greeting("Tom")

//Just keep in mind you don't need to write the parameter name "person" since it's the first parameter listed in the
// function declaration. 

Finally, the last step asks you to print out the "language" property from the tuple. Since, you've already given it an external name, all you have to do is access it using dot notation like this:

println(result.language)

//Note: println is deprecated in Swift 2.0, use print in the future.

Hope all of that helps. Let me know if you have any more questions.