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

Matt Porter
Matt Porter
2,192 Points

Enum downloadStatus switch statement

Im confused as to what the (let failure) Is doing.

enum Status { case Success case Failure(String) }

let downloadStatus = Status.Success

switch downloadStatus { case .Success: println("The download was successful") case .Failure(let failure): println(failure) }

You have associated a string with the Status member Failure. So in the switch statement why are we creating a constant called failure with a lower case?

Wouldn't we create a string like "Download unsuccessful "

Or are we passing a constant in the switch statement and assigning our string to the constant failure? Just seems pretty confusing now we have enum Status member Failure and our constant for its string lowercase failure

David Frenkel
David Frenkel
14,548 Points

Can you provide some more info where this is from?

1 Answer

my you include your code that we can help you objectively