|
Attempting to update my main dashboard view once a user makes updates on their settings page. The issue is, the view does not update. It updates correctly in the database and if I close the app out and reopen it displays the new data correctly. I would like the data to refresh live on the app when updated. I figure I am not using StateObject and ObservedObject correctly. If I can get some insight, help on the issue that'll be great. I think posting the entire code base would be redundant in solving the issue, for now I'll just post each view and how I'm passing data in between the views. I won't post my model class either, since I don't think the problem lies there (as I'm using an observableObject class with my var's all being Published.
|
|
|
|
Please delete your apology. We have ALL BEEN THERE! It's just difficult to help when the code format is blorked like it was. |
|
There's a lot to unpack, so I might not get right to the answer. But some of these comments should help you better organize your code base. For example: You have a model, named And you have a ViewModel, named So here's an example where you might consider adding a computed
In your ViewModel,
|
|
...continued.... Now that this is a little cleaner. Let's look at the In your view, This tells me that whenever the published objects in Also remember, But this is where I run out of steam. I see your Just a guess, because I think some crucial code is missing from your snips. (Also, why? why do you declare structs and classes 1/2 across the screen instead of on the leading edge?) |
|
I tried to copy your code into my XCode so I could take a better look, but there are a bunch of missing closing braces and things that can not be found in scope. So, I can't really tell what is supposed to be going on exactly. But, if I had to guess a reason why the view does not appear to update until after you close and reopen the app, it might be that the changes to your data model may not be happening on the mainActor thread. So, maybe the view is reloading before all of the data actually loads. So, by the time the data finishes loading, the View thinks that it has already updated itself since the last change, and doesn't need to update again even though new data finished loading later. However, when you restart the app after the data has finished loading, then the view shows all of the data that it should. |
|
Obelix First off thank you! The fact you took the time and explained your thought process was so valuable. I appreciate it beyond belief!! Will definately refactor my codebase with your tips in mind. @flyostrich You hero thank you! You nailed it, on the main thread I wasn't updating my model. I slapped an objectwillchange in there, linked it to my model class and viola. A week's problem is now solved. Thank you both for all the help on this again, sincerely appreciate it! |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
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.