iOS Functions in Swift Adding Power to Functions Returning Complex Values


I don't get this can someone help me please?

func coordinates (location: string){
if location == "Eiffel Tower"{
return (48.8582, 2.2945)
  }else if location == "Great Pyramid"{
    return (29.9792, 31.1344)
    }else {
    return (333.8587, 151.2140)

2 Answers

// this is how local and external names work
/// Multiplies the input by 2 and returns the new number
func myFunction (external internal: Int) -> Int {
    return internal*2

// this is how it is used
let answer = myFunction(external: 500) // answer is of type Int

It looks like you're missing the return type in your function declaration. If you don't put -> at the end of your function declaration, Swift expects the function to return nothing, just "return". You're returning a tuple of type (Double, Double), so that needs to be included in your function declaration. Your return statements look fine, otherwise.

Here are some more examples of external/internal names

func multiply(_ firstNumber: Int, _ secondNumber: Int) -> Int{
    return firstNumber* secondNumber
multiply(4,3) // returns 12

// versus

func multiply(input1 firstNumber: Int, input2 secondNumber: Int) -> Int{
    return firstNumber* secondNumber
multiply(input1: 4, input2: 3)

// versus

func multiply(_ firstNumber: Int, and secondNumber: Int) -> Int{
    return firstNumber* secondNumber
multiply(4, and: 3)

The function coordinates(location: String) takes in a String and checks to see if recognizes it as a location. It has two locations that it knows and for which it can return coordinates. If it doesn't recognize the String, it returns default coordinates.

Is there something specific about the function that might be confusing you?

Oh, I didn't read the challenge. I did just now. My answer might not be super helpful. Can you be more specific about what is confusing you?

THank you for answering me, my two problems are first, the useing of the return command, second the local and external names. I don't know how to do a toople without varibles, can you help me with that? I also have some problems on local and external names, they are too confusing. THank you for answering, hope you could help me.

                                                                                                                                                                - THank you Ryan du.