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

Mitihun Vijayasekar
Mitihun Vijayasekar
2,243 Points

How do i return a tuple of two strings.

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

greeting = ("\(greeting), \(language)")
return greeting

}

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

    greeting = "\(greeting), \(language)"
    return greeting
}

1 Answer

Nathan F.
Nathan F.
30,773 Points

You've correctly modified your method signature, which is the first step:

func greeting(person: String) -> (greeting: String,language: String) {

But in the body of your method, you are still only returning greeting, which contains a single value. You need to return a tuple, so pass in both of your variables into your return statement as a tuple.

return (greeting, language)