<!--
{
  "availability" : [
    "macOS: 10.13.0 -",
    "swift: 4.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTLCopyAllDevicesWithObserver(handler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "s:5Metal29MTLCopyAllDevicesWithObserver7handlerSaySo9MTLDevice_pG7devices_So8NSObjectC8observertySoAD_p_So0H16NotificationNameatc_tF"
  },
  "title" : "MTLCopyAllDevicesWithObserver(handler:)"
}
-->

# MTLCopyAllDevicesWithObserver(handler:)

Returns an array of all the Metal GPU devices in the system and registers a notification handler that Metal calls when the device list changes.

```
func MTLCopyAllDevicesWithObserver(handler: @escaping (any MTLDevice, MTLDeviceNotificationName) -> Void) -> (devices: [any MTLDevice], observer: NSObject)
```

## Parameters

`handler`

A notification handler you implement that Metal calls when the system adds or removes a GPU device from the system.

## Return Value

- `devices`: An array of [`MTLDevice`](/documentation/Metal/MTLDevice) instances
- `observer`: An object instance that represents an observer the function creates for you.

## Discussion

Keep a copy of `observer` in your app in case you want to stop receiving notifications. You can stop receiving notifications by passing `observer` to the [`MTLRemoveDeviceObserver(_:)`](/documentation/Metal/MTLRemoveDeviceObserver(_:)) function.

---

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)