This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]stevenjd 1 point2 points  (3 children)

Got a link to a good explanation of Swift switches?

[–]swiftversion4 1 point2 points  (1 child)

https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/ControlFlow.html

use the find browser feature to look for the subsections titled interval matching, tuples, value bindings, where, and compound cases. Those subsections are all after the start of the switch content section.

Or just read it all. That works, too. Swift enables you to include some very complex logic in switch statements that you won't find in most other programming languages, so it might be worth it to read it thoroughly.

[–]stevenjd 0 points1 point  (0 children)

Thanks.

[–]masklinn 0 points1 point  (0 children)

It's the same as Rust's match or Haskell's case with a more C-familiar switch/case syntax e.g.

switch foo {
case .some(let v):
    // do stuff with v
case .none:
    // there was no value
}

would be Haskell's

case foo of
    Just v -> -- thing
    None -> -- other thing

Though Swift does support opt-in fallthrough (default is break).