---
title: "setFocusModeLocked(lensPosition:completionHandler:)"
framework: avfoundation
role: symbol
role_heading: Instance Method
path: "avfoundation/avcapturedevice/setfocusmodelocked(lensposition:completionhandler:)"
---

# setFocusModeLocked(lensPosition:completionHandler:)

Locks the lens position at the specified value, and sets the focus mode to a locked state.

## Declaration

```swift
func setFocusModeLocked(lensPosition: Float, completionHandler handler: (@Sendable (CMTime) -> Void)? = nil)
```

```swift
func setFocusModeLocked(lensPosition: Float) async -> CMTime
```

## Parameters

- `lensPosition`: The lens position. Pass a value of doc://com.apple.avfoundation/documentation/AVFoundation/AVCaptureDevice/currentLensPosition to leave the current lens position unchanged.
- `handler`: A callback the system invokes when the adjustment to the lens position is complete and the doc://com.apple.avfoundation/documentation/AVFoundation/AVCaptureDevice/focusMode-swift.property set to a locked state. If you call this method multiple times, the system calls the completion handlers in FIFO order. The system passes a time value that matches that of the first buffer to which its applied all settings. It synchronizes the timestamp to the device clock, and you must convert the timestamp to the doc://com.apple.avfoundation/documentation/AVFoundation/AVCaptureSession/synchronizationClock prior to comparison with the timestamps of buffers delivered through an doc://com.apple.avfoundation/documentation/AVFoundation/AVCaptureVideoDataOutput. You can pass nil for this parameter if you don’t require this information.

## Discussion

Discussion Calling this method is the only way to set the value of the lensPosition property. This method throws an exception if you set the value to an unsupported level. Before changing the value the lens position, you must call lockForConfiguration() to acquire exclusive access to the device’s configuration properties. Otherwise, setting the value of this property raises an exception. When you finish configuring the device, call unlockForConfiguration() to release the lock and allow other devices to configure the settings.

## See Also

### Setting focus manually

- [isLockingFocusWithCustomLensPositionSupported](avfoundation/avcapturedevice/islockingfocuswithcustomlenspositionsupported.md)
- [lensPosition](avfoundation/avcapturedevice/lensposition.md)
- [currentLensPosition](avfoundation/avcapturedevice/currentlensposition.md)
