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

Michael Cafin
seal-mask
.a{fill-rule:evenodd;}techdegree
Michael Cafin
iOS Development Techdegree Student 1,221 Points

Some pointers needed

Wondering if the following is correct:

  • Would utilizing a Switch be appropriated?
  • Is my return correct (I know it is "void" as of now)

Any other pointers are welcomde

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

    switch location {
        case "Eifel Tower": (48.8582, 2.2945)
        case "Great Pyramid": (29.9792, 31.1344)
        case "Sydney Opera House": (33.8587, 151.2140)
    default: (0, 0)
    }
    return ()

}

3 Answers

Hi Michael,

A switch statement is perfect for this solution, yes! You will need to return the tuple in each case individually. You also need to spell Eiffel correctly, else it'll not work. :smile: :wink:

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

    switch location {
        case "Eiffel Tower": return (48.8582, 2.2945)
        case "Great Pyramid": return (29.9792, 31.1344)
        case "Sydney Opera House": return (33.8587, 151.2140)
        default: return (0, 0)
    }
}

I hope that helps,

Steve.

Michael Cafin
seal-mask
.a{fill-rule:evenodd;}techdegree
Michael Cafin
iOS Development Techdegree Student 1,221 Points

Wow! Have not seen a switch statement like that before where the return is included in each case. But it makes sense.

Thanks for the Eiffel typo (duh!) I confuse it often with the "Eifel Mountain Range" in west Germany :) that is spelled with one "f"

There may be a more elegant way of doing that; I'm no expert. You could set a local variable within the method, assign the tuple to it within each case statement and return that after the switch, perhaps.

I've walked in the Eifel range; very nice part of the world, not that the surroundings of the Eiffel Tower are shabby - also a lovely place! :+1:

Steve.