Reference to static property 'allowsDirectInteraction' is not concurrency-safe because it involves shared mutable state; this is an error in Swift 6

Asked on 10/25/2024

1 search

In Swift 6, the language mode introduces full enforcement of data isolation, which helps prevent accidental sharing of state between tasks and actors. This is particularly relevant when dealing with shared mutable state, such as static properties. The error you're encountering, "Reference to static property 'allowsDirectInteraction' is not concurrency-safe because it involves shared mutable state," is likely due to Swift 6's stricter concurrency checks.

Swift 6 aims to catch concurrency issues at compile time, turning potential runtime data races into compile-time errors. This is achieved by ensuring that shared mutable state is properly isolated, often using actors or other concurrency-safe constructs. If you're dealing with shared mutable state, you might need to refactor your code to use actors or other synchronization mechanisms to ensure concurrency safety.

For more detailed guidance on migrating to Swift 6 and handling concurrency issues, you can refer to the session Migrate your app to Swift 6 (08:53) which discusses adopting concurrency features and ensuring data-race safety.