Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift 2.0 Functions Function Parameters Returning Complex Values

Ben Masel
Ben Masel
2,004 Points

I Don't Really Know What I'm doing!

Please tell me what i have done wrong, how to correct my mistakes and what I've forgot!

functions.swift
// Enter your code below
func getTowerCoordinates(Landmarks: String) -> (lat: Int, Lon: Int) {

    switch Landmarks {
    case "Eiffel Tower": "48.8582,2.2945"
    case "Great Pyramid": "29.9792,31.1344"
    case "Sydney Opera House": "33.8587,151.2140"
    default:
    }

    return getTowerCoordinates("Null")
}

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi again Benjamin Masel! Well, you aren't the first one to get stuck on this challenge, I promise you. For some reason there seems to always be some confusion when moving from if/else statements over to switch statements. Keep in mind that anything that can go in an if/else statement can go in the body of a case statement. But let's take a harder look at your code.

The challenge asks you to return two doubles. But your function is set up to return two integers. It also explicitly states to return the points (0,0) in the default case, but your default is completely empty. And, in fact, the only return statement you have anywhere will return Null. There's no other return statement anywhere. But even if you added the return in front of all those coordinates right now, it still wouldn't work. Remember, the quotes make them strings :smiley: Take a look at my solution and see if it makes sense.

// Enter your code below
func getTowerCoordinates(Landmarks: String) -> (Double, Double) {

    switch Landmarks {
    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:
      return(0.0, 0.0)
    }
}

This code looks at the Landmarks variable. It then goes through and sees if it has a match. If it does, it returns the coordinates as a tuple containing two Double values. Remember, a function will cease to execute once a return statement is reached. Hope this helps! :sparkles:

Ben Masel
Ben Masel
2,004 Points

Thank you! and yes i get it completely! but it says that:

swift_lint.swift:15:1: error: missing return in a function expected to return '(Double, Double)'
}
^
Ben Masel
Ben Masel
2,004 Points

I've tried returning some things but it still can't be compiled!

Ben Masel
Ben Masel
2,004 Points

Got it! You forgot to return a double value in getTowerCoordinates i did: (0.0,0.0)