Another approach is to use:
enumerated()
ForEach(Array(array.enumerated()), id: \.offset) { index, element in
// ...
}
More Related Contents:
- How to make a SwiftUI List scroll automatically?
- SwiftUI: How to pop to Root view
- Deleting list elements from SwiftUI’s List
- Multiple sheet(isPresented:) doesn’t work in SwiftUI
- Initialize @StateObject with a parameter in SwiftUI
- Custom back button for NavigationView’s navigation bar in SwiftUI
- How to detect a tap gesture location in SwiftUI?
- SwiftUI – State change in UITextField causes the frameWidth to grow uncontrolled and ignore bounds/frame
- Sheet inside ForEach doesn’t loop over items SwiftUI
- Fetch data from CoreData for iOS 14 widget
- Using NavigationLink in Menu (SwiftUI)
- First item in a List is always selected
- SwiftUI: Forcing an Update
- ‘Fatal error: index out of range’ when deleting bound object in view
- In SwiftUI, How do I increase the height of a button?
- SwiftUI: Pop to root view when selected tab is tapped again
- Deletable Table with TextField on SwiftUI
- SwiftUI Drag and Drop files
- How to pass one SwiftUI View as a variable to another View struct
- How to use a @FetchRequest with the new searchable modifier in SwiftUI?
- Is SwiftUI backwards-compatible with iOS 12.x and older?
- How to access NSWindow from @main App using only SwiftUI?
- Setting the TimelineProvider refresh interval for Widget
- Thread 1: EXC_BAD_INSTRUCTION when fetching data
- Conditionally use view in SwiftUI
- What is Content in SwiftUI?
- Programmatically navigate to new view in SwiftUI
- URLSession.shared.dataTaskPublisher not working on IOS 13.3
- Highlight a specific part of the text in SwiftUI
- SwiftUI add inverted mask