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

Jason Oliverson
Jason Oliverson
4,230 Points

Make sure you accept a single parameter of type String in your function declaration - Need help figuring this out!

I've been trying this for a while now and I keep getting this response. I've looked at other responses, but nothing I've tried seems to work.

functions.swift
// Enter your code below
func coordinates(location: String) -> (lat: Double, lon: 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:
        print("error--location not found.")
        return (0, 0)
    }
}

1 Answer

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Jason,

That is not a helpful error message! (Paging Pasan Premaratne)

Turns out the problem is that the challenge asks you to give the parameter an external name of for, and an internal name of location. You only gave a single name, which ends up being used for both internal and external. You have to add the word for before location.

Once that's fixed, it will give another unhelpful error message that you need to return a tuple of type (Double, Double). Again, you're doing that, but your labeling does not follow the instructions. They say not to name the returned tuple values. Simply delete your labels lat: and lon:.

Let me know if you have any questions!

Cheers :beers:

-Greg

solution.swift
// Enter your code 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:
        print("error--location not found.")
        return (0, 0)
    }
}
Pasan Premaratne
Pasan Premaratne
Treehouse Teacher

Thanks for tracking this down! I'll improve these error messages