|
I have been having a problem getting a re-render of a view, when a subview updates observable data. This occurs even though CoreData is used, so I added an additional Observable Object class with just a toggle of a Boolean to trigger the rerender.
Here is code referencing the ObservedObject in View A
Here is the code adding the variable and Toggling the value in the View B
I added a button in View A so that I could print the value and the results I see are Bid Picker Score with bids - Save Complete |
|
hi Sandy, your code is saying that View A has defined
and View B has also defined
so View A and View B have distinct bids; they are not referencing the same bid. ideally, you will have a parent view that contains both View A and View B, as in
and, importantly, your definition of
now the ParentView creates and owns a single Bid object; each of the subviews references it. hope that helps, DMG |
|
DMG Yes, I had figured out to remove the initializations in both View A and B, also made the one in view @StateObject, it passes to view B in the call, and now I can see that it is passing from A to B and Back with the correct state change, but it is still NOT updating the view. I had a 30 min lab/call with the Apple WWDC folks, had a CoreData guy and a SwiftUI guy. They said the changes to core Data should have triggered the view and we made changes to about three views in the viewhierarchy declaring the core data classes as ObservedObjects. Did the ParentData Object, and also the ChildData Object, both, and it still never triggered update before we ran out of time. I will try to move instantiation of the @StateObject up the view hierarchy as you suggested to see if that helps. Just easier to try to get a single flag to trigger the re-render if possible. Color me trying to stay optomistic... |
|
|
|
This initial problem has been solved. I took the published property on the observable/observed class and added it in a hidden text field to the view needed to re-render and it solved the problem. I have a different/more interesting problem, which I will open in a different thread. |
|
This initial problem has been solved. I took the published property on the observable/observed class and added it in a hidden text field to the view needed to re-render and it solved the problem. I have a different/more interesting problem, which I will open in a different thread. |
SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.