Skip to content

Instantly share code, notes, and snippets.

@bguidolim
Created January 4, 2026 14:01
Show Gist options
  • Select an option

  • Save bguidolim/4f69c1435d470b77f000cafcfde7d7c7 to your computer and use it in GitHub Desktop.

Select an option

Save bguidolim/4f69c1435d470b77f000cafcfde7d7c7 to your computer and use it in GitHub Desktop.
import SwiftUI
public struct ForEachIndex<ItemType: Identifiable, ContentView: View>: View {
let data: [ItemType]
let content: (Int, ItemType) -> ContentView
public init(_ data: [ItemType], @ViewBuilder content: @escaping (Int, ItemType) -> ContentView) {
self.data = data
self.content = content
}
public var body: some View {
ForEach(Array(zip(data.indices, data)), id: \.1.id) { idx, item in
content(idx, item)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment