---
title: "MIDIGetDevice(_:)"
framework: coremidi
role: symbol
role_heading: Function
path: "coremidi/midigetdevice(_:)"
---

# MIDIGetDevice(_:)

Returns a device from the system.

## Declaration

```swift
func MIDIGetDevice(_ deviceIndex0: Int) -> MIDIDeviceRef
```

## Parameters

- `deviceIndex0`: The index of the device to retrieve.

## Return Value

Return Value A reference to a device, or NULL if an error occurred.

## Discussion

Discussion Call this function to enumerate the devices in the system. To enumerate the entities in the system, walk through the devices and then walk through the device’s entities. When you iterate through the devices and entities in the system, you don’t visit virtual sources and destinations created by other clients. A device iteration returns devices that are offline (they were present in the past but aren’t currently available), while iterations through the system’s sources and destinations don’t include the endpoints of offline devices. Instead, clients typically use MIDIGetNumberOfSources(), MIDIGetSource(_:), MIDIGetNumberOfDestinations() and MIDIGetDestination(_:).

## See Also

### Device lookup

- [MIDIGetNumberOfDevices()](coremidi/midigetnumberofdevices().md)
- [MIDIGetNumberOfExternalDevices()](coremidi/midigetnumberofexternaldevices().md)
- [MIDIGetExternalDevice(_:)](coremidi/midigetexternaldevice(_:).md)
- [MIDIDeviceGetNumberOfEntities(_:)](coremidi/mididevicegetnumberofentities(_:).md)
- [MIDIDeviceGetEntity(_:_:)](coremidi/mididevicegetentity(_:_:).md)
- [MIDIDeviceRef](coremidi/midideviceref.md)
