---
title: "setPreferredDataSource(_:)"
framework: avfaudio
role: symbol
role_heading: Instance Method
path: "avfaudio/avaudiosessionportdescription/setpreferreddatasource(_:)"
---

# setPreferredDataSource(_:)

Sets the preferred audio data source for the port.

## Declaration

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

## Parameters

- `dataSource`: The data source to use.

## Discussion

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 property. (For details, see Configuring standard audio behaviors in the 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.

## See Also

### Managing a Port’s Data Sources

- [dataSources](avfaudio/avaudiosessionportdescription/datasources.md)
- [selectedDataSource](avfaudio/avaudiosessionportdescription/selecteddatasource.md)
- [preferredDataSource](avfaudio/avaudiosessionportdescription/preferreddatasource.md)
