Contents

typeSelectEquivalent(_:)

Sets an explicit type select equivalent text in a collection, such as a list or table.

Declaration

nonisolated func typeSelectEquivalent(_ stringKey: LocalizedStringKey) -> some View

Parameters

  • stringKey:

    The localized string key to use as a type select equivalent for a view in a collection.

Discussion

By default, a type select equivalent is automatically derived from any Text or TextField content in a list or table. In the below example, type select can be used to select a person, even though no explicit value has been set.

List(people, selection: $selectedPersonID) { person in
    Label {
        Text(person.name)
    } icon: {
        person.avatar
    }
}

An explicit type select value should be set when there is no textual content or when a different value is desired compared to what’s displayed in the view. Explicit values also provide a more performant for complex view types. In the below example, type select is explicitly set to allow selection of views that otherwise only display an image.

List(people, selection: $selectedPersonID) { person in
    person.avatar
        .accessibilityLabel(person.name)
        .typeSelectEquivalent(person.name)
}

Setting an empty string value disables text selection for the view, and a value of nil results in the view using its default value.