dabrahams
(Dave Abrahams)
1
I just found an expression, call it “β”, and a type T, such that:
let x = β as T
is legal, but
let x: T = β
is a error. The asymmetry seems pretty unusual to me—can you think of any such instances?—and I was wondering if it was intentional.
What are `T` and β?
typealias T = AnyObject
β := U.self where U is any type.
4 Likes
cukr
2
Yes
import Foundation
let x = NSString()
let y = x as String
let z: String = x // error: 'NSString' is not implicitly convertible to 'String'; did you mean to use 'as' to explicitly convert?
and also the other way around
import Foundation
let x = String()
let y = x as NSString
let z: NSString = x // Cannot convert value of type 'String' to specified type 'NSString'
4 Likes