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

Can't seem to return results without naming what is contained in the tuple? Sorry just a bit confused!

Hey,

Sorry, new to this so I'm sure this is blatantly obvious to everyone except for me... how can I return values within a tuple without using long and lat? if i try to use .1 and .2 to get results it errors out.

Thanks for your help!

T.

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


    switch location {
    case "EiffelTower": (48.8582, 2.2945)
    case "GreatPyramid": (29.9792, 31.1344)
    case "SydneyOperaHouse": (33.8587, 151.2140)
    default: (0.00, 0.00)
    }
return(long, lat)

}

let result = coordinates(for: "EiffelTower")

1 Answer

Jonathan Ruiz
Jonathan Ruiz
2,998 Points

Hi Tomasz for the tuple you don't need to give them any names just declare the type in this case they are both doubles. Since we have a function that returns a tuple of two double values after you write what you want to switch on a case statement. You then return the tuple, in your code that was written separately and was not letting it pass. Also in the default case you just need to write (0,0) they give you that default statement in the directions.

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)
    }
}

Jonathan,

Thanks very much for your help! Really appreciate it.

Best,

Tomasz