|
I'm borrowing a pattern from Paul's UltimatePortfolio app in which I have DataController that handles all things CoreData and it has a I know this error typically occurs when you're trying to update a @Published property within a SwiftUI view's lifecycle methods, such as init(), onAppear(), or onChange() of another @ObservedObject, but I don't think I'm doing any of this in I'm using the 'LiftEvent' in CalculatorView like this:
The problem is that I get the error here:
But this function is doing essentially the same thing as Paul's function for creating a new Issue:
|
|
Thanks for the suggestions, @Obelix. I added 'save()' (and the functions it needs to work) so it exactly matches what Paul is doing but, as I suspected, it didn't fix the problem. About the I don't think it makes sense to move it to the Let me know if you think otherwise. |
|
You're in the elite HWS+ community. Us plebes in the lower decks don't get to see the articles for his Ultimate Portfolio. Nor can we view the vids he posts as solutions to his HWS+ Ultimate Portfolio. To be honest, I was just taking a wild guess as I can't see his code, nor his solutions. Since it didn't work, I deleted my unhelpful post. |
SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free! Sponsor Hacking with Swift and reach the world's largest Swift community! |
|
I can't see the context in which newLiftEvent is being called. Are you sure you're on the main thread? I have had similar problems in one of my apps and the solution was to save the changed object, then set the selected item inside a DispatchQueue.main.async callback. It then forces the update onto the main thread where the UI updates. Might be worth. try. |
|
|
|
Wrap the code and see if it makes a difference.
If you are on the main thread, then there is no significant overhead. If not, the code will just run and your update should happen without error. The overhead of testing which thread you're on is wasted effort. Chances are, if you're not on the main thread and this fixes your problem, then you're always going to be on another thread so the test becomes irrelevant. |
|
I encourage the OP to buy Paul's "Swift Concurrency by Example". I think it is the clearest book he's written. It explains the basis of @barnettsab's advice. |
|
|
|
|
|
No worries. I suspect you are calling this code from a closure and that closure is from a background activity. Without seeing the code where your method is called, I can only guess (and offer the same fix that I did in my own code). |
SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!
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.