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

Can't work it out!

Hey guys,

I'm a little confused with this task.

Can you please tell me what I'm doing wrong?

functions.swift
// Enter your code below

func getTowerCoordinates (location: String) ->(Double,Double){

  switch towerCoordinates{
  case "Eiffel Tower": lat 48.8582, lon 2.2945
  case "Great Pyramid" : lat 29.9793, lon 31.1344
  case "Sydney Opera House" : lat 33.8587, lon 151.2140
  default:  (0,0) }

 }

1 Answer

Michael Reining
Michael Reining
10,101 Points

Hi Matt,

You are close but confusing a few items.

  1. You need to switch on the input parameter name (location)

  2. For each case you just need to return a tuple with two Double values

If you test everything in the playground in Xcode you will get much better feedback and accelerate your learning. It really helps. Give it a try.

Once you do the above, the code should look like this.

// Enter your code below

func getTowerCoordinates (location: String) -> (Double,Double) {

    switch location { // switch on parameter called location
    case "Eiffel Tower": return (48.8582,2.2945) // return tuple with two doubles
    case "Great Pyramid" : return (29.9792,31.1344)
    case "Sydney Opera House" : return (33.8587,151.2140)
    default:  return (0,0) }

}

getTowerCoordinates("Eiffel Tower") // for playground only to see results

I hope that helps,

Mike

PS: If you found the above helpful, be sure to check out my app which breaks code challenges down and really explains things so you can learn faster.

Code! Learn how to program with Swift

https://itunes.apple.com/app/code!-learn-how-to-program/id1032546737?mt=8

PPS: I could not have developed the above app without going through the awesome resources on Team Treehouse. Stick with it. It is so worth it!