---
title: "setDynamicAspectRatio(_:completionHandler:)"
framework: avfoundation
role: symbol
role_heading: Instance Method
path: "avfoundation/avcapturedevice/setdynamicaspectratio(_:completionhandler:)"
---

# setDynamicAspectRatio(_:completionHandler:)

Updates the dynamic aspect ratio of the device.

## Declaration

```swift
func setDynamicAspectRatio(_ dynamicAspectRatio: AVCaptureDevice.AspectRatio, completionHandler handler: (@Sendable (CMTime, (any Error)?) -> Void)? = nil)
```

```swift
func setDynamicAspectRatio(_ dynamicAspectRatio: AVCaptureDevice.AspectRatio) async throws -> CMTime
```

## Parameters

- `dynamicAspectRatio`: The new doc://com.apple.avfoundation/documentation/AVFoundation/AVCaptureDevice/AspectRatio the device should output.
- `handler`: A block called by the device when dynamicAspectRatio is set to the value specified. If you call doc://com.apple.avfoundation/documentation/AVFoundation/AVCaptureDevice/setDynamicAspectRatio(_:completionHandler:) multiple times, the completion handlers are called in FIFO order. The block receives a timestamp which matches that of the first buffer to which all settings have been applied. Note that the timestamp is synchronized to the device clock, and thus must be converted to the doc://com.apple.avfoundation/documentation/AVFoundation/AVCaptureSession/synchronizationClock prior to comparison with the timestamps of buffers delivered via an doc://com.apple.avfoundation/documentation/AVFoundation/AVCaptureVideoDataOutput. You may pass nil for the handler parameter if you do not need to know when the operation completes.

## Discussion

Discussion This is the only way of setting dynamicAspectRatio. This method throws an NSInvalidArgumentException if dynamicAspectRatio is not a supported aspect ratio found in the device’s activeFormat’s supportedDynamicAspectRatios. This method throws an NSGenericException if you call it without first obtaining exclusive access to the device using lockForConfiguration().

## See Also

### Configuring dynamic aspect ratio

- [AVCaptureDevice.AspectRatio](avfoundation/avcapturedevice/aspectratio.md)
- [dynamicAspectRatio](avfoundation/avcapturedevice/dynamicaspectratio.md)
- [dynamicDimensions](avfoundation/avcapturedevice/dynamicdimensions.md)
