<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "tvOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AVFoundation",
  "identifier" : "/documentation/AVFoundation/AVCaptureDevice/setPrimaryConstituentDeviceSwitchingBehaviorLockedWith(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AVFoundation"
    ],
    "preciseIdentifier" : "c:objc(cs)AVCaptureDevice(im)setPrimaryConstituentDeviceSwitchingBehaviorLockedWithDevice:"
  },
  "title" : "setPrimaryConstituentDeviceSwitchingBehaviorLockedWith(_:)"
}
-->

# setPrimaryConstituentDeviceSwitchingBehaviorLockedWith(_:)

Sets the switching behavior of the primary constituent device to locked with the specified device.

```
func setPrimaryConstituentDeviceSwitchingBehaviorLockedWith(_ device: AVCaptureDevice)
```

## Parameters

`device`

The constituent device to lock.

## Discussion

Before locking a virtual camera’s primary constituent device, check that [`isPrimaryConstituentDeviceSwitchingBehaviorLockedWithDeviceSupported`](/documentation/AVFoundation/AVCaptureDevice/isPrimaryConstituentDeviceSwitchingBehaviorLockedWithDeviceSupported) is `true`. If locking is not supported, attempting to lock throws an `NSInvalidArgumentException`. Call [`lockForConfiguration()`](/documentation/AVFoundation/AVCaptureDevice/lockForConfiguration()) to acquire exclusive access to the device’s configuration properties. Once a constituent device is locked, it becomes the [`activePrimaryConstituent`](/documentation/AVFoundation/AVCaptureDevice/activePrimaryConstituent), and [`primaryConstituentDeviceSwitchingBehavior`](/documentation/AVFoundation/AVCaptureDevice/primaryConstituentDeviceSwitchingBehavior-swift.property) is updated to `AVCapturePrimaryConstituentDeviceSwitchingBehaviorLocked`. The virtual camera’s properties remain unchanged. Their effective values can be obtained from the [`activePrimaryConstituent`](/documentation/AVFoundation/AVCaptureDevice/activePrimaryConstituent). To unlock the primary constituent device, set [`primaryConstituentDeviceSwitchingBehavior`](/documentation/AVFoundation/AVCaptureDevice/primaryConstituentDeviceSwitchingBehavior-swift.property) to `AVCapturePrimaryConstituentDeviceSwitchingBehaviorAuto`. This may trigger an immediate update of [`activePrimaryConstituent`](/documentation/AVFoundation/AVCaptureDevice/activePrimaryConstituent). Locking a different primary constituent device without first unlocking the current one is allowed.

If the current [`videoZoomFactor`](/documentation/AVFoundation/AVCaptureDevice/videoZoomFactor) is within the constituent device’s supported range, it will remain unchanged. If it falls outside the range, the zoom factor will automatically be clamped to the nearest supported value. If a zoom ramp is in progress, the ramp target and current position will similarly be updated to stay within the supported range.  If both the target and position are thus clamped to the same value, this will cancel the ramp at that value, otherwise the ramp will continue within the remaining available range at its current velocity.

---

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)