iOS Functions in Swift Adding Power to Functions Returning Complex Values

Tanner Shelton
Tanner Shelton
iOS Development Techdegree Student 1,136 Points

I'm not exactly sure what this is asking or where I'm going wrong.

I'm not exactly sure where "for" fits in here.

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



coordinates(for: "Eiffel Tower")
Rogier Nitschelm
Rogier Nitschelm
iOS Development Techdegree Student 5,411 Points

I am not entirely sure - because I do not know the exact question (I tried looking it up based on the signature of the function you wrote). But I will give it a shot:

In swift it is possible to declare an external function parameter. With this external parameter, you can call the function instead of the internal parameter. Which is nice as it allows for even more English-like function-calling.

func coordinates(for location: String) -> (Double, Double) {
    if location == "Eiffel Tower" {
      return (12.34, 45.56)
   } ...
}

var coordinate = coordinates(for: "Eiffel Tower")  // instead of coordinates(location: "Eiffel Tower")
print(coordinate) // 12.34, 45.56

1 Answer

Emin Grbo
Emin Grbo
13,091 Points

You just mixed some stuff up.

Internal and external coordinates are the arguments you pass TO the function, so they only wanted you to have "for location" when creating it.

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

FOR is external, meaning you will use it only when you call the function later on, not inside of it. (therefore the name :))

coordinates(for: "Eiffel Tower") |

And location is used within a function, like you did, so the only issue is to remove the "for" you added in the "if else" statements :)

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

  if location == "Eiffel Tower" {
  return (48.8582, 2.2945) 
  } else if location == "Great Pyramid" {
  return (29.9792, 31.1344) 
  } else if location == "Sydney Opera House"{
  return (33.8587, 151.2140) 
  } else {
  return (0,0)  
  }

}