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

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,273 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!