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

Jonathan Seymour
Jonathan Seymour
3,119 Points

i don't understand why this challenge won't accept my code to return a tuple

In this question i was asked to modify the given greeting(person: String) function to return a tuple instead of a String, so i changed the return type to (String, String) and changed the value being returned from the single string greeting, to the required tuple of strings (greeting, language).

I can't see what i'm doing wrong here and in Xcode my code compiles the way i was expecting it to, but the challenge will not accept my code saying that my function needs to return the given strings greeting and language; as far as i can see my function is already doing that.

Any help would be really appreciated.

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

    return (greeting, language)
}

1 Answer

Iman Mk
Iman Mk
6,223 Points

Hi Jonathan,

Did you try labeling your return types? Like this:

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

    return (greeting, language)
}

It should work now! Let me know if you have any questions.