Returns the given instance cast unconditionally to the specified type.
SDK
- Xcode 7.1+
Framework
- Swift Standard Library
Declaration
func unsafeDowncast<T>(_ x: Any Object, to type: T.Type) -> T where T : AnyObject
Parameters
x
An instance to cast to type
T
.type
The type
T
to whichx
is 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 unsafe
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
.
Warning
This function trades safety for performance. Use unsafe
only when you are confident that x is T
always evaluates to true
, and only after x as! T
has proven to be a performance problem.