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

Alex Wride
Alex Wride
4,420 Points

I don't understand the error I'm getting for Challenge task 2 of 3 on the Tuple section.

I keep getting the error, "You need assign the return value of the 'greeting' function to 'result'" What am i doing wrong? I've tried adjusting the syntax but i can't quite figure it out.

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

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

1 Answer

Richard Lu
Richard Lu
20,185 Points

So what you have is a function named greeting with 1 parameter named person. When you use your function, you pass it 2 arguments.

in order to stop the compiler error, what you want to do is change the code to this

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

    return (greeting, language)
}

var result = greeting("Tom")

This might fix the problem. Let me know how it goes :)

Alex Wride
Alex Wride
4,420 Points

That worked perfectly, thanks.