ForEach

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

A view that creates views based on data. This view itself has no visual representation. Adding a background to this view, for example, will have no effect.

  • Declaration

    Swift

    public var viewStore: ViewValues
  • Declaration

    Swift

    public var body: View { get }
  • Creates views based on uniquely identifiable data, by using a custom id.

    The id value of each data should be unique.

    Declaration

    Swift

    public init(_ data: Data, id: KeyPath<Data.Element, ID>, content: @escaping (Data.Element) -> Content)

    Parameters

    data

    The identified data that the ForEach instance uses to create views dynamically.

    id

    A keypath for the value that uniquely identify each data.

    content

    The view builder that creates views dynamically.

Available where ID == Data.Element.ID, Data.Element: Identifiable

  • Creates views based on uniquely identifiable data.

    The id value of each data should be unique.

    Declaration

    Swift

    public init(_ data: Data, content: @escaping (Data.Element) -> Content)

    Parameters

    data

    The identified data that the ForEach instance uses to create views dynamically.

    content

    The view builder that creates views dynamically.

Available where Data == Range<Int>, ID == Int

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

    To compute views on demand over a dynamic range use ForEach(_:id:content:).

    Declaration

    Swift

    public init(_ data: Range<Int>, content: @escaping (Int) -> Content)