iOS Functions in Swift Adding Power to Functions Returning Complex Values

Hasseeb Hussain
Hasseeb Hussain
2,154 Points

Functions?

Can't quite figure out what's gone wrong..

functions.swift
// Enter your code below

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

switch location {
case "Eiffel Tower": lat = 48.8582, lon = 2.2945
case "Great Pyramid": lat = 29.9792, lon = 31.1344
case "Sydney Opera House": lat = 33.8587, lon = 151.2140
default: lat = 0, lon = 0
}

return location 

}

1 Answer

Jennifer Nordell
STAFF
Jennifer Nordell
Treehouse Staff

Hi there! This challenge asks you to make a function that returns two Doubles as a tuple. It should accept one argument which is a string with the external name for and the local name location. Your function says that it should return two Double named lat and lon, but the challenge asks for them to remain unnamed for this example.

We send in location as a string. This will match (or should) with one of our cases. But your function only returns one thing. It returns the String that was sent in. At this point, if they were to send in "Eiffel Tower", your code would return "Eiffel Tower". However, it will not compile in this state as the return type does not match what you've said the return type should be.

But let me show you one example of a case which returns a latitude and longitude as an example:

  case "Eiffel Tower": return(48.8582, 2.2945)

I feel like you can get the rest of it with this hint, but let me know if you're still stuck! :sparkles:

Hasseeb Hussain
Hasseeb Hussain
2,154 Points

Hey, I just got it. Thanks for the help!

Jennifer Nordell
Jennifer Nordell
Treehouse Staff

Hasseeb Hussain what it means is that you've told the function that it's going to return two Doubles, one named lat and one named lon. But it wants a return type without names.

func coordinates(for location: String) -> (Double, Double)  //returning two doubles without a name

Hope this helps! :sparkles: