I have a custom struct
called myObjectHolder
and it has an array of a custom struct
(called myObject
) called myArray
.
I try to fetch the data I store in Firebase-Firesrtore
and to append it to the array (using a function that converts the Firebase
document to myObject
).
I try to do it like this:
struct myObjectHolder {
var myArray = [myObject]()
private func fetchMyObjects() {
let db = Firestore.firestore().collection("myObjects").getDocuments { (querySnapshot, err) in
for document in querySnapshot!.documents {
self.myArray.append(self.myObjectFromDocument(document: document)) //Error
}
}
}
For some reason, when I try to append the new myObject
to myArray
, I receive this error message:
Cannot use mutating member on immutable value: 'self' is immutable
Does anybody know how can I resolve it? (I am using SwiftUI
it matters)
Thank you!