why is optional chaining required in an if let statement
Posted
by
b-ryan ca
on Stack Overflow
See other posts from Stack Overflow
or by b-ryan ca
Published on 2014-06-06T03:20:15Z
Indexed on
2014/06/06
3:24 UTC
Read the original article
Hit count: 201
swift-language
Why would the Swift compiler expect me to write
if let addressNumber = paul.residence?.address?.buildingNumber?.toInt() { }
instead of just writing:
if let addressNumber = paul.residence.address.buildingNumber.toInt() { }
The compiler clearly has the static type information to handle the conditional statement for the first dereference of the optional value and each following value. Why would it not continue to do so for the following statements?
© Stack Overflow or respective owner