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 Functions in Swift Adding Power to Functions Returning Complex Values

Eunice Torres
Eunice Torres
2,278 Points

swift tuple functions

I would like some help on tuple within a function. I need to have a function with a local of location and return two double. i.e. user needs to input a name, if it matches a case then print out its coordinates.

functions.swift
// Enter your code below

func coordinates(for location: String) -> (lat: Double, long: Double)
{
    let value //Possibly need a constnt of Value... 

    switch location
    {
    case "Eiffel Tower": print(48.8582, 2.2945)
    case "Great Pyramid": print(29.9792, 31.1344)
    case "Sydney Opera House": print(33.8587, 151.2140)
    default: print(0,0)
    }

    return () //Need to return Tuple of string to double...
}

2 Answers

Jeff McDivitt
Jeff McDivitt
23,970 Points

Here is what is wrong with your code :)

  1. The task states not to name the return Doubles so there is no need for the lat and long
  2. You don't need the let value
  3. The task does not ask you to print anything; therefore, you can replace your print with return and you will be returning the tuple the you are looking for
  4. You can remove the return () you have at the end

Your correct code will look like the below

func coordinates(for location: String) -> (Double, Double) {

    switch location {
    case "Eiffel Tower":
        return (48.8582,2.2945)
    case "Great Pyramid":
        return (29.9792,31.1344 )
    case "Sydney Opera House":
        return (33.8587,151.2140)
    default:
        return (0,0)
    }

}
Eunice Torres
Eunice Torres
2,278 Points

Thanks Jeff! I spent two day trying to figure it out, but it seems I was overthinking it.