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

Alex Nwarueze
Alex Nwarueze
2,172 Points

maybe I don't understand the question I'm being asked

I've given this problem all I got the passed few days. I really could use some help so I can move forward.

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

    return greeting
}

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Some languages can't return more than one thing at a time. However, Swift can. What it's asking here is for you to return both the String greeting and the String language. Your code is currently just returning greeting. Take a look at my solution:

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

    return (greeting, language)
}

Before we return multiple items, though, we have to first tell the function that that's what we're going to do. This is why we have the (greeting: String, language:String) in the first line. It tells Swift that we're planning on returning two values of the String type with these names. Happy coding! :smiley: