Using SwiftData I have " @Query var hands: [Hand]". My understanding is that the variable hands will be an array of Hand objects. The is in my view.
I have a function, in a different class, that adds to this array. As the parameter for the function I have " hands: inout [Hand]", It is inout cause in the function I have "hands.append"
The call looks like "common.record(hands: &hands" I get an error "Cannot pass immutable object..."
I understand, kind of, why I get the error. I am trying to use an object I can not change, the hands array, passing it as something I will change.
If I declare a variable as an array of [Hand] I can use it in the call, cause I defined as a variable. I think my problem is that the variable created by the @query is a let, not a var.
I know frameworks like to do things their way and I do not fully understand swift so is there a way swift would like me to do this?
I have a view, that does not itself use the array, and the array is backed by data kept in SwiftData. When I press a button I want to call a function that will add an element to the array.