---
title: TableColumnForEach
framework: swiftui
role: symbol
role_heading: Structure
path: swiftui/tablecolumnforeach
---

# TableColumnForEach

A structure that computes columns on demand from an underlying collection of identified data.

## Declaration

```swift
nonisolated struct TableColumnForEach<Data, ID, RowValue, Sort, Content> where Data : RandomAccessCollection, ID : Hashable, RowValue == Content.TableRowValue, Sort == Content.TableColumnSortComparator, Content : TableColumnContent
```

## Overview

Overview Use TableColumnForEach to create columns based on a RandomAccessCollection of some data type. Either the collection’s elements must conform to Identifiable or you need to provide an id parameter to the TableColumnForEach initializer. The following example shows the interface for an AudioSampleTrack, which h as a collection of AudioSample across a dynamic number of AudioChannels. The Table is created for displaying rows for each sample. It has one static column for the sample’s timestamp and uses a TableColumnForEach instance to produce a column for each of the audio channels in the track. struct AudioChannel: Identifiable {     let name: String     let id: UUID }

struct AudioSample: Identifiable {     let id: UUID     let timestamp: TimeInterval     func level(channel: AudioChannel.ID) -> Double }

@Observable class AudioSampleTrack {     let channels: [AudioChannel]     var samples: some RandomAccessCollection<AudioSample> { get } }

struct ContentView: View {     var track: AudioSampleTrack

var body: some View {         Table(track.samples) {             TableColumn("Timestamp (ms)") { sample in                 Text(sample.timestamp, format: .number.scale(1000))                     .monospacedDigit()             }             TableColumnForEach(track.channels) { channel in                 TableColumn(channel.name) { sample in                     Text(sample.level(channel: channel.id),                          format: .number.precision(.fractionLength(2))                     )                     .monospacedDigit()                 }                 .width(ideal: 70)                 .alignment(.numeric)             }         }     } }

## Topics

### Creating the collection

- [init(_:content:)](swiftui/tablecolumnforeach/init(_:content:).md)
- [init(_:id:content:)](swiftui/tablecolumnforeach/init(_:id:content:).md)

### Accessing collection content

- [content](swiftui/tablecolumnforeach/content.md)
- [data](swiftui/tablecolumnforeach/data.md)

## Relationships

### Conforms To

- [TableColumnContent](swiftui/tablecolumncontent.md)

## See Also

### Creating columns

- [TableColumn](swiftui/tablecolumn.md)
- [TableColumnContent](swiftui/tablecolumncontent.md)
- [TableColumnAlignment](swiftui/tablecolumnalignment.md)
- [TableColumnBuilder](swiftui/tablecolumnbuilder.md)
