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

Bruno Fernandes
Bruno Fernandes
2,413 Points

Completely stuck in Task 3

This is the first challenge that I get completely stuck, either I have to re-watch all the chapter again, or this exercise needs some more explanation. :(

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

    return (greeting, language)
}

var result = greeting(person: "Tom")
println(greeting.language)

1 Answer

The task says to print out the value of language from the instance of greeting, "result." What you're doing is calling it on the greeting function itself.

println(result.language)
Bruno Fernandes
Bruno Fernandes
2,413 Points

And how do I do this? I still don't know it what I have to do...

Bruno Fernandes
Bruno Fernandes
2,413 Points

Ok, for some reason it only worked after I inverted (language: String, greeting: String) to (greeting: String, language: String) is this something I did wrong or a bug in the simulator?

Oh, I didn't even notice that. It may have something to with at the top you've said you want to return (language: String, greeting: String), but at the end of the function you return it in this order: (greeting, language)

Now that shouldn't affect the output of result.language, however, the challenge may have been checking all your work to make sure there weren't any other errors (which in this case there were).