<!--
{
  "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:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI6ToggleVA2A4TextVRszrlE_7sources4isOnACyAEG10Foundation23LocalizedStringResourceV_qd__s7KeyPathCy7ElementQyd__AA7BindingVySbGGtcSkRd__lufc::OverloadGroup"
  },
  "title" : "init(_:sources:isOn:)"
}
-->

# init(_:sources:isOn:)

Creates a toggle representing a collection of values that generates its
label from a localized string resource.

```
@export(implementation) nonisolated init<C>(_ titleResource: LocalizedStringResource, sources: C, isOn: KeyPath<C.Element, Binding<Bool>>) where C : RandomAccessCollection
```

## Parameters

`titleResource`

Text resource for the toggle’s localized title, that
describes the purpose of the toggle.

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

## Discussion

This initializer creates a [`Text`](/documentation/SwiftUI/Text) view on your behalf. See
`Text` for more information about localizing strings.

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("Enable all alarms", sources: $alarms, isOn: \.isOn)
```

---

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)