How do I return the original value from any in Swift?
You declared a1
as Optional
, which is a type enum
, and then assign the optional (enum) value a2
. Note that the enumeration is not Int
, so attempting to dynamically migrate a2
to Int
using as?
fails. As a result, it is a3
set to nil
.
To fix this, you can explicitly expand the optional value, for example:
let a2:Any = a1!
source to share