<!--
{
  "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/AVAudioSession/setPreferredInput(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AVFAudio"
    ],
    "preciseIdentifier" : "c:objc(cs)AVAudioSession(im)setPreferredInput:error:"
  },
  "title" : "setPreferredInput(_:)"
}
-->

# setPreferredInput(_:)

Sets the preferred input port for audio routing.

```
func setPreferredInput(_ inPort: AVAudioSessionPortDescription?) throws
```

## Parameters

`inPort`

An [`AVAudioSessionPortDescription`](/documentation/AVFAudio/AVAudioSessionPortDescription) object that describes the port to use for input.

## Discussion

Setting the preferred input port requests a change to the input audio route. To determine whether the change has taken effect, use the [`currentRoute`](/documentation/AVFAudio/AVAudioSession/currentRoute) property.

The value of the `inPort` parameter must be one of the [`AVAudioSessionPortDescription`](/documentation/AVFAudio/AVAudioSessionPortDescription) objects in the [`availableInputs`](/documentation/AVFAudio/AVAudioSession/availableInputs) array. If this parameter specifies a port that isn’t already part of the current audio route and the app’s session controls audio routing, this method initiates a route change to use the preferred port.

You must set a preferred input port 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)