> For the complete documentation index, see [llms.txt](https://swift-packages.gitbook.io/materialuikit/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://swift-packages.gitbook.io/materialuikit/components/switch.md).

# Switch

Represents a Material UI styled switch for toggling boolean states.

### Overview

The `Switch` view is used to toggle a boolean state on or off with a Material UI style switch. It allows users to toggle between checked and unchecked states.

To use the `Switch`, initialize it with a title key and a binding to the boolean state.

### Initializer

Creates a switch with a specified title and state binding.

```swift
Switch(_ titleKey: String, isOn: Binding<Bool>)
```

### Parameters

<table data-header-hidden><thead><tr><th width="185"></th><th></th></tr></thead><tbody><tr><td><strong>Parameter</strong></td><td><strong>Description</strong></td></tr><tr><td><code>titleKey</code></td><td>The title key of the switch.</td></tr><tr><td><code>isOn</code></td><td>A binding to a boolean value that determines the on/off state of the switch.</td></tr></tbody></table>

### Example

```swift
@State private var isSwitchOn = false

var body: some View {
    Container {
        Switch("Toggle Switch", isOn: $isTurnedOn)
    }
}
```

<figure><picture><source srcset="https://2931569195-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHpwjDgYAa64eKF8AGmeE%2Fuploads%2FcCcEcQgFAF64Nfb5JkPc%2FSwitch%20Dark.png?alt=media&amp;token=e267c622-fd63-4608-ad3e-47d49e11fa35" media="(prefers-color-scheme: dark)"><img src="https://2931569195-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHpwjDgYAa64eKF8AGmeE%2Fuploads%2Frejf7v4qqV1Iag75BEHB%2FSwitch%20Light.png?alt=media&amp;token=0df373c1-5507-4277-8023-4f1597f05519" alt=""></picture><figcaption></figcaption></figure>
