unsafeDowncast(_:to:)
Returns the given instance cast unconditionally to the specified type.
Declaration
func unsafeDowncast<T>(_ x: AnyObject, to type: T.Type) -> T where T : AnyObjectParameters
- x:
An instance to cast to type
T. - type:
The type
Tto whichxis cast.
Return Value
The instance x, cast to type T.
Discussion
The instance passed as x must be an instance of type T.
Use this function instead of unsafeBitcast(_:to:) because this function is more restrictive and still performs a check in debug builds. In -O builds, no test is performed to ensure that x actually has the dynamic type T.