Skip to main content

SwiftUI - publishing changes from background threads is not allowed

The purple warning notification of annoyance recently came my way!  I received the following warning:

Publishing changes from background threads is not allowed; make sure to publish values from the main thread (via operators like receive(on:)) on model updates.

 

What was happening?

The functionality of the code uses URLSession to get a user's name via API and the display is simple piece that initially message of Hello {user}.

Subscribe to warning