#21: Pattern Matching with Variable Values
Question
// Swift Quiz
— objc.io (@objcio) July 10, 2019
import Foundation
var x = 42
let result: Result<Int, Error> = .success(x)
x = 21
switch result {
case .success(x):
print(x)
case .failure(_):
print("Error")
default:
print("Default")
}
// What’s the output?
Solution
Solution: Default
— objc.io (@objcio) July 11, 2019
Note that there's no `let` inside the first case, instead it uses the `x` variable. This is equivalent to writing `case .success(21)`.https://t.co/s7500CWmAg