|
I have completed the BucketList project by following the instructions to make the project conform to MVVM. But I am still getting the purple warning message "Publishing changes from within view updates is not allowed, this will cause undefined behavior." It is showing up in my BucketListApp.swift file and nowhere else, so I'm not sure what this would mean. The warning shows on the line that just has @main on it.
Did anybody else run into this problem, or have I just messed something up while following the instructions? |
|
The compiler is lying to @ostrich:
This is the error message:
This is a clear error, but may be tricky to find. In short, what causes any What the purple message is telling you is that while the OS is updating one of your views ( Wait whut? Think about it. While you are redrawing a view struct, let's say a Weird! |
|
I understand the concept of what we are trying to do. But I find it strange that even by following the instructions provided, I still get the warning message, even when Paul says that it should disappear at this point. (Unless I missed a step somewhere that I can't seem to find.)
The only line I can see where the data model might be modified by something outside of the ViewModel is
And Paul tells us in the video instructions that there isn't much we can do about that line so just leave it as is. So, if that is the problem, I don't know how to fix it. |
|
I commented out this section of my code, and it seems to make the warnings go away. So, the problem must be in this segment of code. This leads me to believe that the binding Unless I am supposed to make this entire Map View a property of my ViewModel maybe 🧐
|
|
@Ostrich puts on his thinkin' cap....
So without seeing your viewModel, I can only guess what's on the other side. (I've not completed this lesson!) Indeed, if you have a view model that writes to a remote data source (or even to disk?) you may have that code on a background thread. In that case (just guessing) you may be trying to update your view right now, even though the model may take a few seconds to save, publish and notify the views of the updated data. (Previous thoughts may be pure nonsense. But it's a thread -ha! pun! - I would follow.) |
|
I've discovered that a lot of people seem to be having problems with this since updating to XCode 14 https://developer.apple.com/forums/thread/711899?page=2 So, I guess there is probably some kind of bug causing this issue for me right now. It has just been very confusing for me since I am just barely trying to learn about this stuff. |
BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.
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.