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

Returning Values of Functions to Variables

I'm being asked to create a variable named result that returns the tuple assigned to a function's return, but I'm still not getting it...

if the function's return is assigned as -> (greeting: String, language: String), and if I'm supposed to assign that tuple to a variable called result, shouldn't it look like this:

var result = (greeting: String, language: String)

I'm sure it's something super simple that I'm missing, but if you have any insight, let me know.

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

2 Answers

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Jonathon,

You've got a couple of issues with your code, but mostly, you're just over-complicating it for yourself :). Did you pass the first challenge? Your code should have looked like this:

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

    return (greeting: greeting, language: language)
}

Then, the second challenge is just asking you to assign the result of calling the greeting function you just defined in the first challenge to a variable result. You need to do this outside the function, not inside, as you've done. We won't change the function at all for this step:

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

    return (greeting: greeting, language: language)
}

var result = greeting("Tom") // see how easy that was? :)

Totally cleared a lot of stuff up for me. Thanks for taking the time to answer my question!

Greg Kaleka
Greg Kaleka
39,021 Points

No problem! Glad I could help out.

var result = (greeting: String, language: String) return greeting(person: "Tom") You can't declare a tuple like that, watch the video again ! And you're trying to return the result of a function... In this function ! You have to return a variable !