<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/unsafeDowncast(_:to:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s14unsafeDowncast_2toxyXl_xmtRlzClF"
  },
  "title" : "unsafeDowncast(_:to:)"
}
-->

# 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.

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

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

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)