I agree with Oliver Borchert and Airspeed speed : this problem should be resolved using a protocol.
However, you can complete the cast you asked for using this syntax:
let values = allValues as Any as [Person]
Now I see 2 problems:
I think the next version is safer because you directly evaluate type T.
class Things<T>{ func doSomething() { let allValues = [T]() // populate allValues.... if T.self is Person.Type { println("List of Person") let values = allValues as Any as [Person] } } }
Important: I provided this code to show the syntax. I donβt like this abborder (again, the protocol will be better), because the Things class contains entity-specific logic. Ideally, Things should not know anything about Person , because Things are a common class.
source share