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

# init(_:sources:selection:content:)

Creates a picker that generates its label from a localized string
resource.

```
@export(implementation) nonisolated init<C>(_ titleResource: LocalizedStringResource, sources: C, selection: KeyPath<C.Element, Binding<SelectionValue>>, @ContentBuilder content: () -> Content) where C : RandomAccessCollection
```

## Parameters

`titleResource`

A localized string resource that describes the
purpose of selecting an option.

`sources`

A collection of values used as the source for displaying
the Picker’s selection.

`selection`

The key path of the values that determines the
currently-selected options. When a user selects an option from the
picker, the values at the key path of all items in the `sources`
collection are updated with the selected option.

`content`

A view that contains the set of options.

## Discussion

If the wrapped values of the collection passed to `sources` are not all
the same, some styles render the selection in a mixed state. The
specific presentation depends on the style.  For example, a Picker
with a menu style uses dashes instead of checkmarks to indicate the
selected values.

In the following example, a picker in a document inspector controls the
thickness of borders for the currently-selected shapes, which can be of
any number.

```
enum Thickness: String, CaseIterable, Identifiable {
    case thin
    case regular
    case thick

    var id: String { rawValue }
}

struct Border {
    var color: Color
    var thickness: Thickness
}

@State private var selectedObjectBorders = [
    Border(color: .black, thickness: .thin),
    Border(color: .red, thickness: .thick)
]

Picker(
    "Border Thickness",
    sources: $selectedObjectBorders,
    selection: \.thickness
) {
    ForEach(Thickness.allCases) { thickness in
        Text(thickness.rawValue)
    }
}
```

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

---

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)