Wednesday, March 13, 2024
HomeiOS Developmentios - Swift 6 Error with Non-Remoted World Shared Mutable State in...

ios – Swift 6 Error with Non-Remoted World Shared Mutable State in EnvironmentKey


I’ve encountered a concurrency security problem in Swift 5.10 StrictConcurrency mode that I am struggling to resolve. I am working with an EnvironmentKey construction that features a static property outlined as an asynchronous closure returning an optionally available customized actor. Right here is the simplified code snippet:

struct DataHandlerKey: EnvironmentKey {
    static var defaultValue: @Sendable () async -> Hiya? = { nil }
}

actor Hiya {}

The defaultValue is a closure marked with @Sendable that asynchronously returns an optionally available Hiya actor occasion. Nonetheless, Swift 5.10 with StrictConcurrency compiler raises a concurrency security error, stating:

Static property 'defaultValue' shouldn't be concurrency-safe as a result of it's non-isolated world shared mutable state; that is an error in Swift 6.

I perceive that the difficulty is expounded to the static property probably introducing non-isolated world shared mutable state, however I am uncertain learn how to regulate my code to stick to Swift 6’s enhanced concurrency security necessities. The Hiya actor is designed to be concurrency-safe, but I am unable to make use of it as meant on this context.

Any insights, strategies, or references to related documentation could be enormously appreciated. Thanks upfront to your assist!



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments