0

Trying to figure out why my ForEach loop isn’t updating. I have the model marked as ObservedObject and have done everything I could to make sure the updates were happening. I even saw that the model was being updated while printing.

class Model {
    var array: [Int]
}
…
struct ModelView: View {
    @ObservedObject var model: Model
var body: some View {
    List {
         ForEach(model.array.indices, id:\.self) { index in
…
        }.onDelete(perform: delete)
    }
}

The row is animating and acting like it is deleting and does delete in the model, however the deleted row animates back in and the original data set is shown!

Kudit
  • 4,212
  • 2
  • 26
  • 32

1 Answers1

0

I figured it out. I needed to make the array in my model object with the @Published property wrapper. Doing that fixed everything!

Kudit
  • 4,212
  • 2
  • 26
  • 32