FunctionSwift

    unsafeDowncast(_:to:)

    Returns the given instance cast unconditionally to the specified type.

    func unsafeDowncast<T>(_ x: AnyObject, to type: T.Type) -> T where T : AnyObject

    Parameters

    x

    An instance to cast to type T.

    type

    The type T to which x is cast.

    Returns

    The instance x, cast to type T.

    Overview

    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.