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

# setPrimaryConstituentDeviceSwitchingBehavior(_:restrictedSwitchingBehaviorConditions:)

Sets the switching behavior of the primary constituent device.

```
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 [`AVCaptureDevice.PrimaryConstituentDeviceSwitchingBehavior.restricted`](/documentation/AVFoundation/AVCaptureDevice/PrimaryConstituentDeviceSwitchingBehavior-swift.enum/restricted)     requires that you set this argument to an empty option set.

## 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`](/documentation/AVFoundation/AVCaptureDevice/activePrimaryConstituentDeviceSwitchingBehavior) property. If the value equals `.unsupported`, attempting to configure its switching behavior results in an error.

```swift
// 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`](/documentation/AVFoundation/AVCaptureMovieFileOutput), you may override the switching behavior by calling the movie file output’s [`setPrimaryConstituentDeviceSwitchingBehaviorForRecording(_:restrictedSwitchingBehaviorConditions:)`](/documentation/AVFoundation/AVCaptureMovieFileOutput/setPrimaryConstituentDeviceSwitchingBehaviorForRecording(_:restrictedSwitchingBehaviorConditions:)) method.

---

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)