|
So, I followed along with the HWS+ video for the day 61 challenge after I got stuck with a non-helping error message from Xcode. Afterward, I did a few changes and moved the logic from the ContentView file to a Network and Data Manager class (which is using a singleton). I put it into the environment as a @StateObject in the App.Swift file. Anyway, as I was tinkering away, I made changed the List in ContentView to show a badge with the number of friends each user has. And here the weird behavior started. When I run the app in the simulator or on my phone, the number of friends changes between restarting the app. What is going on? The JSON file doesn’t change. And I'm not getting any errors when decoding or saving
|
|
Very good point @fi20100!!! I think many of us did not pay attention to that bug. Even without moving logic to data manager or observable object it messes up with cachedFriend. So the reason I suppose is with concurrency. Core Data has a function to help guarantee Core Data tasks always happen one after another in a serial queue, no matter where that task is added from. This function is called After modifying the
|
|
So also just updated logic to have observable object and can confirm that it works as we expect it to work. I have created observable object as follows:
and then we can adjust to our content view to hanlde only UI stuff.
|
|
|
|
If this is still relevant or maybe some other people out there may, and most probably will have similar issues with that.
This behavior is the result of |
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!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.