Swift Cast Generics Type

I’m trying to cast a generic type to its super class.

class Foo : NSObject {
}
class Test<T> {
    let value: T
    init(_ value: T) {
        self.value = value
    }
}

let c = Test(Foo())
let v = c as Test<AnyObject>

But on the line

let v = c as Test<AnyObject>

I get ‘Foo’ is not identical to ‘AnyObject’

While I can do that with built-in Arrays

let array1 = [Foo(), Foo()]
let array2 = array1 as [AnyObject]


Download swift.cast.generics.type.zip
Direct Link


Download


Download swift.cast.generics.type.zip
Mediafire


Download


Download swift.cast.generics.type.zip
Unlimitzone


Download

Both comments and pings are currently closed.

Comments are closed.