---
title: "unsafeDowncast(_:to:)"
framework: swift
role: symbol
role_heading: Function
path: "swift/unsafedowncast(_:to:)"
---

# unsafeDowncast(_:to:)

Returns the given instance cast unconditionally to the specified type.

## Declaration

```swift
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.

## Return Value

Return Value The instance x, cast to type T.

## Discussion

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. warning: This function trades safety for performance. Use unsafeDowncast(_:to:) 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.

## See Also

### Instance Casting

- [unsafeBitCast(_:to:)](swift/unsafebitcast(_:to:).md)
