Skip to main content
added 323 characters in body
Source Link
Stone
  • 3.7k
  • 1
  • 24
  • 20

Another approach is to use:

enumerated()

Update for Swift 6.2:

Swift 6.2 introduces Collection conformances for enumerated(). (SE-0459)

ForEach(array.enumerated(), id: \.offset) { index, element in // ... } 

Before Swift 6.2:

ForEach(Array(array.enumerated()), id: \.offset) { index, element in // ... } 

Source: https://alejandromp.com/blog/swiftui-enumerated/

Another approach is to use:

enumerated()

ForEach(Array(array.enumerated()), id: \.offset) { index, element in // ... } 

Source: https://alejandromp.com/blog/swiftui-enumerated/

Another approach is to use:

enumerated()

Update for Swift 6.2:

Swift 6.2 introduces Collection conformances for enumerated(). (SE-0459)

ForEach(array.enumerated(), id: \.offset) { index, element in // ... } 

Before Swift 6.2:

ForEach(Array(array.enumerated()), id: \.offset) { index, element in // ... } 

Source: https://alejandromp.com/blog/swiftui-enumerated/

Source Link
Stone
  • 3.7k
  • 1
  • 24
  • 20

Another approach is to use:

enumerated()

ForEach(Array(array.enumerated()), id: \.offset) { index, element in // ... } 

Source: https://alejandromp.com/blog/swiftui-enumerated/