I am new to SwiftUI and I am trying to get the index for the following ForEach Loop
ForEach(self.postViewModel.posts, id: \.postId) { post in
HStack(alignment: .top, spacing: 25) {
Header(post : post)
Footer(post: post)
I have tried using indices as in the following:
ForEach(self.postViewModel.posts.indices, id: \.postId) { post in
but I got this error
Value of type 'Range<Array<Post>.Index>.Element' (aka 'Int') has no member 'postId'
I have also tried using index but obviously it wouldn't work since index isn't in the loop
ForEach(self.postViewModel.posts, id: \.postId) { post in
HStack(alignment: .top, spacing: 25) {
Header(post : post)
Footer(post: post)
Text("#\(index)").frame(width: 45, height: 30)