How to use actor properties from the main actor without async/await

Oscar de la Hera Gomez
Two flowers that represent Swift and Xcode side by side.Beneath them sits the text "Reference Actor Properties from the Main Actor."

Use static properties to allow your app to access or reference an actor's property without async/await.

A screenshot of Xcode showing how global actor properties cannot be referenced outside of a task and require async/await within a task.

If you attempt to access the property of an actor that is not a main actor in a UIView, outside a Task or within a Task without using await Xcode will alert you of one of the following errors:

  • Expression is 'async' but is not marked with 'await'.
  • Actor-isolated property 'counter' can not be referenced from the main actor.

This can become a problem when trying to update UI without waiting for the property to return its value and would ideally happen on the main thread whilst maintaining the thread-safe, concurrent behavior of the actors.

A screenshot of Xcode showing how static global actor properties can be accessed without async/await and outside of a task.

This can be resolved by making the actor's property static, enabling it to be accessed or used on the main thread 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