> ## Documentation Index
> Fetch the complete documentation index at: https://docs.duca.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Swift ForEach snippet

> SwiftUI snippet that generates multiple Text() components based on the items in an array.

### Base ForEach generation

```swift SomeView.swift theme={null}
import SwiftUI

struct SomeView: View {
    @State private var someArray: [String] = ["Igor"] 

    var body: some View {
        ForEach(someArray, id: \.self) { item in
            HStack {
                Text("\(item)")
                    .font(.title3)
                    .fontWeight(.semibold)
            }
        }
    }
}

#Preview {
    SomeView()
}
```

### ForEach snippet + Delete item

```swift SomeView.swift theme={null}
import SwiftUI

struct SomeView: View {
    @State private var someArray: [String] = ["Igor"] 

    var body: some View {
        ForEach(someArray, id: \.self) { item in
            HStack {
                Text("\(item)")
                    .font(.title3)
                    .fontWeight(.semibold)
                    .onTapGesture {
                        someArray.remove(at: someArray.firstIndex(of: person ) ?? 0)
                    }
            }
        }
    }
}

#Preview {
    SomeView()
}
```
