#41: Optional Overload
Question
// Swift Quiz
— objc.io (@objcio) January 22, 2020
// by @tammofreese
func foo() throws -> Int { 0 }
func foo() throws -> Int? { 1 }
let a = (try? foo())
let b = (try? foo())!
let result = (a == b)
// What’s the value of result? (Swift 5)
Solution
Solution: true
— objc.io (@objcio) January 24, 2020
In most other cases (e.g. when you write `try foo()`), Swift complains about an ambiguous use of `foo()`. However, with a `try?` it chooses the optional overload.https://t.co/s7500CWmAg