How to use actor properties from the main actor without async/await
Use static properties to allow your app to access or reference an actor's property without async/await.
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.
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.