<!--
{
  "availability" : [
    "macOS: 15.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Virtualization",
  "identifier" : "/documentation/Virtualization/VZUSBController/detach(device:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Virtualization"
    ],
    "preciseIdentifier" : "c:objc(cs)VZUSBController(im)detachDevice:completionHandler:"
  },
  "title" : "detach(device:completionHandler:)"
}
-->

# detach(device:completionHandler:)

Detaches a USB device from the controller.

```
func detach(device: any VZUSBDevice, completionHandler: @escaping ((any Error)?) -> Void)
```

## Parameters

`device`

The USB device to detach.

`completionHandler`

A block the framework calls after the device detaches, or on an error. The error parameter that passes to the block is `nil` if detaching the device is successful. The framework calls the block on a VM’s queue.

## Discussion

If the device successfully detaches from the controller, it disappears from the [`usbDevices`](/documentation/Virtualization/VZUSBController/usbDevices) property, the framework sets its [`usbController`](/documentation/Virtualization/VZUSBDevice/usbController) property to `nil,` and the completion handler returns `nil`.

If the device doesn’t have an attachment to the controller at the time of calling the detach method, the process fails with [`VZError.Code.deviceNotFound`](/documentation/Virtualization/VZError/Code/deviceNotFound).

You need to call this method on the virtual machine’s queue.

## See Also

[`VZUSBDevice`](/documentation/Virtualization/VZUSBDevice)

A protocol that represents a USB device in a VM.



---

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)