Code:
class AppStore: ObservableObject {
@Published var settings = Settings()
}
struct Settings {
var account = Account()
}
class Account {
@Published username
}
@EnvironmentObject appStore = AppStore()
VStack {
TextField("username", &appStore.settings.username)
Button("Change") {
appStore.settings.username += "a"
}
}
What happened:
appStore.settings.username += "a"
can not trigger the update of the view. But input to the TextField can trigger the update of the view.
Question:
I understand why appStore.settings.username += "a"
can not trigger the update of the view. The ObservableObject can only observe the change of value, but the account is refrence type. So when we change the property of account, there is no value change in appStore. But I don't know why the second situation can happen