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

How do I go about this?

How do I go about this? I've no idea what I'm missing or not doing? Can someone help me please?

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

    return greeting
}

2 Answers

Chris Adamson
Chris Adamson
132,143 Points

The first part of the challenge is looking for the return type to be updated to a tuple rather then just a String. So you update the return type, and then in the return statement, return the two items, greeting and language in a tuple.

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

    return (greeting, language)
}
Sam Chaudry
Sam Chaudry
25,519 Points

Based on your code it seems to be running fine. I've checked in a playground and it seems to be ok and is printing "Hello Sam", to the console. Your code seems to be fine it might just be failing as you need to run it and pass in a String parameter of something.

func greeting(person: String) -> String {

let language = "English"
let greeting = "Hello \(person)"

return greeting

}

var greetings = greeting("Sam");

//Prints: Hello Sam