How to update actor properties from the main actor

Use static properties to allow your app to alter or update an actor's property within the main actor.

Oscar de la Hera Gomez
Written by Oscar de la Hera Gomez
First published on 11/01/2023 at 09:53
Last Updated on 11/01/2023 at 10:19
<p>Two flowers that represent Swift and Xcode side by side. Beneath them sits the text "Update Actor Properties from the Main Actor."</p>

Use static properties to allow your app to alter or update an actor's property within the main actor.

SubscribeDownload Open Source Project
<p>A screenshot of Xcode showing how you cannot update a global actor property within a Main Actor, even if it's in a task.</p>

If you attempt to update the property of an actor that is not a main actor in a UIView, outside a Task or within a Task Xcode will alert you with the following error:

  • Actor-isolated property can not be mutated from the main actor.
<p>A screenshot of XCode demonstrating how static global actor properties can be updated within a Main Actor or within a task.</p>

This can be resolved by making the actor's property static, enabling it to be updated on the main thread or within a task as if it were a normal property whilst keeping the remaining actor properties and functionality outside of the main thread.

Looking to learn more about things you can do with Swift and XCode ?

Search our blog to find educational content on learning how to use Swift and XCode.

Search our Blog

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
SubscribeContact UsVisit our BlogView our ServicesView our Work

Partner with us

We would love to get to know you and see how we can help your organization with its goals and needs.
Let's Talk

Stay Informed

Get occasional updates about our company, research, and product launches.
Subscribe