Skip to content

Commit 8aba5f9

Browse files
authored
Create README.md
1 parent 30ec782 commit 8aba5f9

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# IndexedForEach
2+
3+
## Motivation
4+
The purpose of using IndexedForEach is to read array's element and its index in safe way.
5+
As using `.enumerated()` is unsafe way because of the index does not always start from 0.
6+
7+
## Usage
8+
9+
```
10+
import SwiftUI
11+
12+
struct ContentView: View {
13+
let numbers = [1, 2, 3]
14+
15+
var body: some View {
16+
VStack {
17+
IndexedForEach(data: numbers) { index, element in
18+
Text("\(index): \(element)")
19+
}
20+
}
21+
}
22+
}
23+
```

0 commit comments

Comments
 (0)