Change to @Published var in @EnvironmentObject not reflected immediately

前端 未结 3 1332
臣服心动
臣服心动 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:34

    Changing

    final class UserData: NSObject, ObservableObject  {
    

    to

    final class UserData: ObservableObject  {
    

    does fix the issue in Xcode11 Beta6. SwiftUI does seem to not handle NSObject subclasses implementing ObservableObject correctly (at least it doesn't not call it's internal willSet blocks it seems).

提交回复
热议问题