<!--
{
  "availability" : [
    "iOS: 5.0.0 -",
    "iPadOS: 5.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 10.7.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AVFoundation",
  "identifier" : "/documentation/AVFoundation/AVCaptureOutput/connection(with:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AVFoundation"
    ],
    "preciseIdentifier" : "c:objc(cs)AVCaptureOutput(im)connectionWithMediaType:"
  },
  "title" : "connection(with:)"
}
-->

# connection(with:)

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

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

## Parameters

`mediaType`

A media type such as [`video`](/documentation/AVFoundation/AVMediaType/video) or [`audio`](/documentation/AVFoundation/AVMediaType/audio).

## Return Value

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

## Discussion

---

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)