What does this print?
enum Result {
case ok(Int)
case err(String)
}
let r = Result.ok(42)
if case .ok(let v) = r {
print(v)
}
Try it in the online Swift Playground →
[spoiler title="Solution"]
Answer:
42
Explanation:
Pattern matching with `if case` extracts the associated value from the enum case.
[/spoiler]