How to update actor properties from the main actor

Oscar de la Hera Gomez
Two flowers that represent Swift and Xcode side by side. Beneath them sits the text "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.

A screenshot of Xcode showing how you cannot update a global actor property within a Main Actor, even if it's in a task.

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.
A screenshot of XCode demonstrating how static global actor properties can be updated within a Main Actor or within a task.

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.

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.
delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details