I’ve a struct:
struct Demo {
struct Knowledge {
var worth: Int
}
var information: [Data]
}
after which in some view I’ve:
struct SomeView: View {
@Binding var demo: Demo
var physique: some View {
Button(motion: {
demo.information[validIndex].worth = 5
}) {
Picture(systemName: "plus.circle")
.resizable()
.body(width: 50.0, peak: 50.0, alignment: .middle)
}
}
}
assume the var information: [Data]
has greater than 5 components in it, and we’re simply making an attempt to replace an present worth once we press this button in SomeView
. If I exploit SomeView
like this:
struct DisappearView: View {
@Binding var demo: Demo
var physique: some View {
ZStack {
// different views/shapes, and so on
SomeView(demo: $demo)
}
.onAppear {
// do some stuff
}
.onDisappear {
// do some stuff
}
}
}
the write line, demo.information[validIndex].worth = 5
upon button press triggers the .onDisappear
within the mother or father View, and I can not work out why. I’ve used the debugger to step by means of and execute the code line by line, the array replace appears to work once I write it as an expression within the debugger, but when I resume the code it boots out of the view and triggers .onDisappear
. If I remark out the write line, .onDisappear
is not triggered once I press the button.