<!--
{
  "availability" : [
    "iOS: 4.2.0 -",
    "iPadOS: 4.2.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreMIDI",
  "identifier" : "/documentation/CoreMIDI/MIDIGetDevice(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Core MIDI"
    ],
    "preciseIdentifier" : "c:@F@MIDIGetDevice"
  },
  "title" : "MIDIGetDevice(_:)"
}
-->

# MIDIGetDevice(_:)

Returns a device from the system.

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

## Parameters

`deviceIndex0`

The index of the device to retrieve.

## Return Value

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

## 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()`](/documentation/CoreMIDI/MIDIGetNumberOfSources()), [`MIDIGetSource(_:)`](/documentation/CoreMIDI/MIDIGetSource(_:)), [`MIDIGetNumberOfDestinations()`](/documentation/CoreMIDI/MIDIGetNumberOfDestinations()) and [`MIDIGetDestination(_:)`](/documentation/CoreMIDI/MIDIGetDestination(_:)).

---

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)