"at any time" needs clarification, otherwise it's not obvious when it would be possible to mutate model at all:
var body: some View {
Text(model.text) // i shall not mutate model here, now that i know it
Button(...) { // button action
(1) but can i mutate model here? (1)
DispatchQueue.main.async {
(2) or i mutate model here?
}
}
Text(model.something that might depend on (1))
}
...
some async event (e.g. network or timer, etc) --
is it safe to mutate model there? or are there any rules
when it is ok and when it is not? e.g. is timer dispatched
on main loop guaranteed to run outside of any "body" call?
ideally SwiftUI + Swift shall prohibit me doing the wrong thing... if that's possible. with "mutating" method above i'm getting runtime error, but sometimes not even this. ideally that needs to be a compilation error:
var body: some View {
Text(model.mutatingGetText) // compilation error: can't do that
Button(...) { // button action
model.mutatingMethod1() // (1) ok (right?)
DispatchQueue.main.async {
model.mutatingMethod1() // (2) ok (right?)
}
Text(model.something that might depend on (1))
}
}