---
title: "init(sources:isOn:label:)"
framework: swiftui
role: symbol
role_heading: Initializer
path: "swiftui/toggle/init(sources:ison:label:)"
---

# init(sources:isOn:label:)

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

## Declaration

```swift
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

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") }

## See Also

### Creating a toggle for a collection

- [init(_:sources:isOn:)](swiftui/toggle/init(_:sources:ison:).md)
- [init(_:image:sources:isOn:)](swiftui/toggle/init(_:image:sources:ison:).md)
- [init(_:systemImage:sources:isOn:)](swiftui/toggle/init(_:systemimage:sources:ison:).md)
