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

This challenge is not letting me finish! I think I have the correct result, but it gives me an error.

I don't know what I'm supposed to do... I'm pretty sure I followed the instructions exactly, my code seems to be fine. If I copy this into Xcode and print variable "result" it prints the tuple perfectly.

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

    return (language, greeting)
}

var result = greeting("Tom")

1 Answer

OK, it turns out that the challenge requires the "greeting" constant to be the 1st part of the tuple, and the "language" constant to be the 2nd. Like so.

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

    return (greeting, language)
}

var result = greeting("Tom")

I think the challenge should be adjusted to accept both. It's unnecessarily frustrating not being able to complete the course because of something like this.