---
title: "MTLCopyAllDevicesWithObserver(handler:)"
framework: metal
role: symbol
role_heading: Function
path: "metal/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.

## Declaration

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

Return Value

## Discussion

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(_:) function.

## See Also

### Locating GPUs

- [Finding multiple GPUs on an Intel-based Mac](metal/finding-multiple-gpus-on-an-intel-based-mac.md)
- [Getting the GPU that drives a view’s display](metal/getting-the-gpu-that-drives-a-views-display.md)
- [MTLCopyAllDevices()](metal/mtlcopyalldevices().md)
- [MTLRemoveDeviceObserver(_:)](metal/mtlremovedeviceobserver(_:).md)
- [CGDirectDisplayCopyCurrentMetalDevice(_:)](coregraphics/cgdirectdisplaycopycurrentmetaldevice(_:).md)
- [MTLDeviceNotificationHandler](metal/mtldevicenotificationhandler.md)
- [MTLDeviceNotificationName](metal/mtldevicenotificationname.md)
