12 Replies
      Latest reply on Aug 13, 2019 1:17 PM by jtayler
      SpaceMan Level 1 Level 1 (10 points)

        I have a major issue with @ObservedObject.

         

        I have the following statement

        @ObservedObject var model: UserData

        in a good number of views and before Beta 5, I did not have to pass this variable into the preview, nor did I have to pass his variable into other views which already have the above statement.

         

        But now I do have to and it's a mess.  Is there anyway around this?

        • Re: @ObservedObject Issue
          feldur Level 1 Level 1 (0 points)

          I have the same concern, having duly crammed parameter passes everywhere.

           

          Moreover, at one time this all worked well using BindableObject on the class and @ObjectBinding on the objective truth objects. When beta 5 arrived, I converted to ObservableObject, Identifiable and @ObservedObject. Having done that, the views no longer update. I've verified the external events happen, the objective truth variable changes, and the willChange.send() fires, but the views remain unsullied by any updates.

           

          My other two big gripes are (1) live views are missing, and (2) I can discover no apparent SwiftUI way to respond to orientation changes.

          • Re: @ObservedObject Issue
            Trickshot_SWE Level 1 Level 1 (0 points)

            Same error here after installing Catalina Beta 5

              • Re: @ObservedObject Issue
                SpaceMan Level 1 Level 1 (10 points)

                The SwiftUI Apple tutorial is using @EnvironmentObject instead of @ObservedObject.  That appears to be working for me.

                  • Re: @ObservedObject Issue
                    jtayler Level 1 Level 1 (10 points)

                    SpaceMan, can you help us understand what you did exactly and what you think is going on with the @ObservedObject protocol?

                     

                    I kind of assume since this is Xcode beta 5 installing onto Beta 6 and failing while working as expected on the beta 5 Simulator that this is a bug in the Beta 6 iOS release and we may get an update or the Xcode will be updated very shortly to resolve this.

                     

                    Do you think this is a permanent change?

                • Re: @ObservedObject Issue
                  MaksGal Level 1 Level 1 (0 points)

                  Don't forget to implement:

                  let objectWillChange = ObservableObjectPublisher()
                  

                  in your ObservableObject class

                  • Re: @ObservedObject Issue
                    jtayler Level 1 Level 1 (10 points)

                    I am also having troubles with anything relating to @ObservableObject and I see some effort to use @EnvironmentObject instead -- but this requires some amount of making changes and I notice there is no xcode update to go with the Beta?

                     

                    Has anyone from Apple verified this? Seems like a major bug late in the beta?

                      • Re: @ObservedObject Issue
                        SpaceMan Level 1 Level 1 (10 points)

                        Check out the following website describing the differences between @EnvironmentObject and @ObservedObject.

                         

                        https://mecid.github.io/2019/06/12/understanding-property-wrappers-in-swiftui/

                        • Re: @ObservedObject Issue
                          wilm Level 1 Level 1 (0 points)

                          I had exactly the same problem with macOS 10.15  Beta5. Neither @ObservableObject nor @EnvironmentObject in a View (SwiftUI) worked. Changing a parameter in the observed object (or environment object) and sending the message from its objectWillChange Publisher did not result in updating the View.

                           

                          I could solve this problem in my code with one single line:

                          adding "let objectWillChange: ObservableObjectPublisher = ObservableObjectPublisher()" to the observed object (environment object).

                           

                          Even though there is a default implementation of this variable after adding "ObservableObject" protocol declaration it seems not to work properly.

                           

                          After adding this line everything worked as expected. Before no message ever reached the subscribers.

                        • Re: @ObservedObject Issue
                          jtayler Level 1 Level 1 (10 points)

                          @ObservableObject does not work on any device running Beta 6 that I have been able to test.

                           

                          We're using xCode beta 5 which is odd, but @ObservableObject code runs as expected while using xcode and simulator.

                           

                          ObservableObject does not seem to work on Watch simulator at all.

                           

                           

                          Can anyone confirm this? Apple?

                           

                           

                          seems like this would be in the release notes or noted somewhere?

                          • Re: @ObservedObject Issue
                            jtayler Level 1 Level 1 (10 points)

                            If this happens to everyone, would't there be tons of posts on here?

                             

                            Can anyone confirm that most folks do not have this issue?

                             

                            Anything else known at this time?