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

James Robertson
James Robertson
1,934 Points

Decomposing Turples

Im trying to complete this task, Im not sure if Im reading it completely wrong. I have created a variable (as asked), I have named it result (as asked), I have then made the result = the return(greeting) and specified the greeting shall be "Tom" ---> return(greeting: "Tom")

I'm not sure where I am going wrong please help :)

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

    return greeting

    var result = return greeting(person: "Tom")
}

2 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi James,

You're almost there, you do however have a couple of problems with your code.

  1. You're not returning a tuple from your greeting function
  2. You have some invalid syntax are your first return statement which shouldn't be there

The below is the final code you should have.

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

    return (greeting, language)
}

var result = greeting("Tom")

NOTE: When calling functions you don't need to include the parameter name in the function declaration, only if it's declared with # in the function do you need to use something like greeting(person: "Tom").

James Robertson
James Robertson
1,934 Points

OMG Thank you! This helps so much makes it a lot clearer! :)