---
title: "setPrimaryConstituentDeviceSwitchingBehavior(_:restrictedSwitchingBehaviorConditions:)"
framework: avfoundation
role: symbol
role_heading: Instance Method
path: "avfoundation/avcapturedevice/setprimaryconstituentdeviceswitchingbehavior(_:restrictedswitchingbehaviorconditions:)"
---

# setPrimaryConstituentDeviceSwitchingBehavior(_:restrictedSwitchingBehaviorConditions:)

Sets the switching behavior of the primary constituent device.

## Declaration

```swift
func setPrimaryConstituentDeviceSwitchingBehavior(_ switchingBehavior: AVCaptureDevice.PrimaryConstituentDeviceSwitchingBehavior, restrictedSwitchingBehaviorConditions: AVCaptureDevice.PrimaryConstituentDeviceRestrictedSwitchingBehaviorConditions)
```

## Parameters

- `switchingBehavior`: The switching behavior to set on the device.
- `restrictedSwitchingBehaviorConditions`: Sets the conditions during which the system restricts switching cameras. Setting the switching behavior to a value other than doc://com.apple.avfoundation/documentation/AVFoundation/AVCaptureDevice/PrimaryConstituentDeviceSwitchingBehavior-swift.enum/restricted requires that you set this argument to an empty option set.

## Discussion

Discussion Use this method to configure the camera switching behavior of a capture device. Before calling it, determine if a device supports configuring its device switching behavior by querying the device’s activePrimaryConstituentDeviceSwitchingBehavior property. If the value equals .unsupported, attempting to configure its switching behavior results in an error. // Exit early if the device doesn't support configuring switching behavior. guard captureDevice.activePrimaryConstituentDeviceSwitchingBehavior != .unsupported else { return } captureDevice.setPrimaryConstituentDeviceSwitchingBehavior(.auto, restrictedSwitchingBehaviorConditions: []) When recording using an instance of AVCaptureMovieFileOutput, you may override the switching behavior by calling the movie file output’s setPrimaryConstituentDeviceSwitchingBehaviorForRecording(_:restrictedSwitchingBehaviorConditions:) method.

## See Also

### Restricting camera switching

- [primaryConstituentDeviceSwitchingBehavior](avfoundation/avcapturedevice/primaryconstituentdeviceswitchingbehavior-swift.property.md)
- [primaryConstituentDeviceRestrictedSwitchingBehaviorConditions](avfoundation/avcapturedevice/primaryconstituentdevicerestrictedswitchingbehaviorconditions-swift.property.md)
- [activePrimaryConstituentDeviceSwitchingBehavior](avfoundation/avcapturedevice/activeprimaryconstituentdeviceswitchingbehavior.md)
- [activePrimaryConstituentDeviceRestrictedSwitchingBehaviorConditions](avfoundation/avcapturedevice/activeprimaryconstituentdevicerestrictedswitchingbehaviorconditions.md)
- [activePrimaryConstituent](avfoundation/avcapturedevice/activeprimaryconstituent.md)
- [AVCaptureDevice.PrimaryConstituentDeviceSwitchingBehavior](avfoundation/avcapturedevice/primaryconstituentdeviceswitchingbehavior-swift.enum.md)
- [AVCaptureDevice.PrimaryConstituentDeviceRestrictedSwitchingBehaviorConditions](avfoundation/avcapturedevice/primaryconstituentdevicerestrictedswitchingbehaviorconditions-swift.struct.md)
- [supportedFallbackPrimaryConstituentDevices](avfoundation/avcapturedevice/supportedfallbackprimaryconstituentdevices.md)
- [fallbackPrimaryConstituentDevices](avfoundation/avcapturedevice/fallbackprimaryconstituentdevices.md)
