<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: -",
    "macOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AVFAudio",
  "identifier" : "/documentation/AVFAudio/AVReadOnlyAudioPCMBuffer/channelData(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AVFAudio"
    ],
    "preciseIdentifier" : "s:8AVFAudio24AVReadOnlyAudioPCMBufferV11channelDatayAC07ChannelG0OSiF"
  },
  "title" : "channelData(_:)"
}
-->

# channelData(_:)

Returns read-only access to a specific channel’s data.

```
func channelData(_ index: Int) -> AVReadOnlyAudioPCMBuffer.ChannelData
```

## Parameters

`index`

The zero-based channel index.

## Return Value

A `ChannelData` enum containing the channel’s sample data.

## Discussion

The returned `ChannelData` is tied to the lifetime of this buffer and provides
type-safe access to the channel’s sample data.

- Example:

> Note: Provides access to valid data only (up to `frameLength`).

```swift
for channelIndex in 0..<Int(buffer.format.channelCount) {
    let channelData = buffer.channelData(channelIndex)
    switch channelData {
    case .float(let samples):
        // Process Float32 data
        for frame in 0..<samples.count {
            let value = samples[frame]
        }
    case .int16(let samples):
        // Process Int16 data
    case .int32(let samples):
        // Process Int32 data
    }
}
```

---

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)