<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/Toggle/init(sources:isOn:label:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI6ToggleV7sources4isOn5labelACyxGqd___s7KeyPathCy7ElementQyd__AA7BindingVySbGGxyXEtcSkRd__lufc"
  },
  "title" : "init(sources:isOn:label:)"
}
-->

# init(sources:isOn:label:)

Creates a toggle representing a collection of values with a custom label.

```
nonisolated init<C>(sources: C, isOn: KeyPath<C.Element, Binding<Bool>>, @ContentBuilder label: () -> Label) where C : RandomAccessCollection
```

## Parameters

`sources`

A collection of values used as the source for rendering the
Toggle’s state.

`isOn`

The key path of the values that determines whether the toggle
is on, mixed or off.

`label`

A view that describes the purpose of the toggle.

## Discussion

The following example creates a single toggle that represents
the state of multiple alarms:

```
struct Alarm: Hashable, Identifiable {
    var id = UUID()
    var isOn = false
    var name = ""
}

@State private var alarms = [
    Alarm(isOn: true, name: "Morning"),
    Alarm(isOn: false, name: "Evening")
]

Toggle(sources: $alarms, isOn: \.isOn) {
    Text("Enable all alarms")
}
```

---

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)