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

functions

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

functions.swift
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.