# Switch

### 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="/files/J5nnMwXuxHsss2Q2Lwb4" media="(prefers-color-scheme: dark)"><img src="/files/Y6r1GUBaNRbNXZEjNpo2" alt=""></picture><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://swift-packages.gitbook.io/materialuikit/components/switch.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
