Generic Structure

ForEach

The collection of underlying identified data that SwiftUI uses to create views dynamically.

Declaration

struct ForEach<Data, ID, Content> where Data : RandomAccessCollection, ID : Hashable

Topics

Creating a Collection of Views

init(Data, content: (Data.Element) -> Content)

Creates an instance that uniquely identifies and creates views across updates based on the identity of the underlying data.

init(Range<Int>, content: (Int) -> Content)

Creates an instance that computes views on demand over a given constant range.

init(Data, id: KeyPath<Data.Element, ID>, content: (Data.Element) -> Content)

Creates an instance that uniquely identifies and creates views across updates based on the provided key path to the underlying data’s identifier.

Accessing Content

var content: (Data.Element) -> Content

A function you can use to create content on demand using the underlying data.

var data: Data

The collection of underlying identified data that SwiftUI uses to create views dynamically.

Applying Standard Modifiers

View Modifiers

Configure this view and the views it contains by applying standard modifiers.

Relationships

Conforms To

See Also

Lists and Scroll Views

struct List

A container that presents rows of data arranged in a single column.

struct ScrollView

A scrollable view.

protocol DynamicViewContent

A type of view that generates views from an underlying collection of data.

protocol Identifiable

A class of types whose instances hold the value of an entity with stable identity.

enum Axis

The horizontal or vertical dimension in a 2D coordinate system.