Change to @Published var in @EnvironmentObject not reflected immediately

前端 未结 3 1328
臣服心动
臣服心动 2020-12-01 21:54

In this specific case, when I try to change an @EnvironmentObject\'s @Published var, I find that the view is not invalidated and updated immediatel

3条回答
  •  难免孤独
    2020-12-01 22:31

    In Xcode 11 GM2, If you have overridden objectWillChange, then it needs to call send() on setter of a published variable.

    If you don't overridden objectWillChange, once the published variables in @EnvironmentObject or @ObservedObject change, the view should be refreshed. Since in Xcode 11 GM2 objectWillChange already has a default instance, it is no longer necessary to provide it in the ObservableObject.

提交回复
热议问题