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

Not sure what I'm doing wrong when it comes to returning the correct values for each case statement...

Compiler error says to makes sure I'm returning the correct values for each case statement.

functions.swift
// Enter your code below
func coordinates (for location: String) -> (Double, Double) {
      var locationCoordinates = (0.0, 0.0)
        switch location {
          case "Eiffel Tower": print(48.8582,2.2945)
          case "Great Pyramid": print(29.9792, 31.1344)
          case "Sydney Opera House": print(33.8587, 151.2140)
          default: print(0.0, 0.0)
          }
     return (0.0, 0.0) 
}

1 Answer

Jhoan Arango
Jhoan Arango
14,575 Points

Hello:

Basically we are creating a function that will return a tuple, remember that when returning a tuple, is very important to return the amount of values in the tuple, in this case we want to return 2 doubles. Some tuples may have more than 2 values and they may even be different types.

You are going to switch the parameter location, and do each case as a "String" with the names of each location provided to you by the challenge. They must be strings, because that is the parameter's type.

Then since we did not named the labels in the tuples, then we do not use the "lat: 00.000, 00.000", we only use the "Doubles".

// Enter your code below

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

  switch location {
  case "Eiffel Tower": // String
    return  (48.8582, 2.2945) // Return a tuple with Doubles without the names
  case "Great Pyramid":
    return  (29.9792, 31.1344)
  case "Sydney Opera House" :
    return (33.8587, 151.2140)
  default:
    return (0,0)
  }

}

If you have any more questions, please tag me.

Good luck

Just having trouble retaining proper syntax sometimes. I feel like not having a Mac to practice on X-Code is showing. But Thanks, Jhoan. And thanks for offering to help in the future :)