<!--
{
  "availability" : [
    "iOS: 7.0.0 -",
    "iPadOS: 7.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AVFAudio",
  "identifier" : "/documentation/AVFAudio/AVAudioSessionPortDescription/setPreferredDataSource(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AVFAudio"
    ],
    "preciseIdentifier" : "c:objc(cs)AVAudioSessionPortDescription(im)setPreferredDataSource:error:"
  },
  "title" : "setPreferredDataSource(_:)"
}
-->

# setPreferredDataSource(_:)

Sets the preferred audio data source for the port.

```
func setPreferredDataSource(_ dataSource: AVAudioSessionDataSourceDescription?) throws
```

## Parameters

`dataSource`

The data source to use.

## Discussion

Call this method to request a change to the audio session’s preferred data source. To determine whether the change has taken effect, inspect the [`selectedDataSource`](/documentation/AVFAudio/AVAudioSessionPortDescription/selectedDataSource) property. (For details, see Configuring standard audio behaviors in the [`AVAudioSession`](/documentation/AVFAudio/AVAudioSession) class reference).

If the port is in use, changing this setting is likely to result in a route reconfiguration.

Set a preferred data source only after setting the audio session’s category and mode, and activating the session.

---

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)