Please, can someone explain why I can add another eventArray if I define the instance (t2Array) in onAppear while, if I declare it as @State (t3Array) at the beginning of the struct, I get the error: Cannot use mutating member on immutable value: ‘self’ is immutable
Struct for both is:
struct T2 {
var name : String
var eventArray : [String] }
The following works fine in “onAppear”:
var t2Array = [T2(name: "T2", eventArray: ["event1"])]
t2Array[0].eventArray.append("event2")
If I do the following, I get the error
@State var t3Array:[T2]?
and in “onAppear” the error is at the append of event2:
t3Array = [T2(name: "T2", eventArray: ["event1"])]
self.t3Array[0].eventArray.append("event2"). //<<<-- error marked here