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

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
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

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
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

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: