Is it possible to cast Any to an Optional?
For Swift 2.0, you can use the following:
let x: Int? = 10
let y: Any = x
let z = Mirror(reflecting: y).descendant("Some") as? Int
Or as a function:
func castToOptional<T>(x: Any) -> T? {
return Mirror(reflecting: x).descendant("Some") as? T
}
let x: Int? = 10
let y: Any = x
let z: Int? = castToOptional(y)
Or you can do this if you don't like Reflection:
func castToOptional<T>(x: Any) -> T {
return x as! T
}
let x: Int? = 10
let y: Any = x
let z: Int? = castToOptional(y)