---
title: "connection(with:)"
framework: avfoundation
role: symbol
role_heading: Instance Method
path: "avfoundation/avcaptureoutput/connection(with:)"
---

# connection(with:)

Returns the first connection with an input port of a specified media type.

## Declaration

```swift
func connection(with mediaType: AVMediaType) -> AVCaptureConnection?
```

## Parameters

- `mediaType`: A media type such as doc://com.apple.avfoundation/documentation/AVFoundation/AVMediaType/video or doc://com.apple.avfoundation/documentation/AVFoundation/AVMediaType/audio.

## Return Value

Return Value The first capture connection that has the specified media type, or nil if no connection for the media type exists.

## See Also

### Accessing connections

- [connections](avfoundation/avcaptureoutput/connections.md)
- [AVCaptureOutput.DataDroppedReason](avfoundation/avcaptureoutput/datadroppedreason.md)
