Here are two implementations that I'd expect to be equivalent, but
something's different because the first example crashes, whereas the second
example does not crash.
What's the difference between these two? Why does casting to Any before the
forced downcast to T have any effect?
Example 1: (`unexpectedly found nil while unwrapping an Optional value`)
```
func cast<T>(_ name: String?) -> T {
return name as! T
}
debugPrint((cast(nil) as String?) as Any))
```
Example 2: (prints `nil`)
```
func cast<T>(_ name: String?) -> T {
return (name as Any) as! T
}
debugPrint((cast(nil) as String?) as Any)
```
_______________________________________________
swift-users mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-users