iOS Functions in Swift Adding Power to Functions Returning Complex Values

For this challenge don't return a named tuple. Just use return types

I've tried not naming the returns, but it doesn't seem to work, this code works in playground but not here - although the coordinates might be coming with the wrong decimal place in playground.

functions.swift
// Enter your code below
func coordinates(for location: String) -> (lat: Double, lon: Double) {
    var lon = 0.0
    var lat = 0.0
    switch location{
    case "Eiffel Tower": lon = 48.8582; lat = 2.2945
    case "Great Pyramid": lon = 29.9792; lat = 31.1344
    case "Sydney Opera House": lon = 33.8587 ; lat = 151.2140

    default: lon = 0.0; lat = 0.0
    }
    return (lon, lat)
}

1 Answer

tromben98
tromben98
13,272 Points

Hi Lee!

The instructions specifies that you should return a unnamed tuple. That means that you should just specify the types of the values in the tuple.

Here is the solution:

func coordinates(for location: String) -> (Double, Double) {
    var lon = 0.0
    var lat = 0.0
    switch location{
    case "Eiffel Tower": lon = 48.8582; lat = 2.2945
    case "Great Pyramid": lon = 29.9792; lat = 31.1344
    case "Sydney Opera House": lon = 33.8587 ; lat = 151.2140

    default: lon = 0.0; lat = 0.0
    }
    return (lon, lat)
}

Best regards, Jonas

Thanks Jonas, Got it now :)

Rodney Gile
Rodney Gile
4,714 Points

Whew! Was having a heck of a time getting through this one. Thanks for your help!