square / Cleanse

Lightweight Swift Dependency Injection Framework
Other
1.78k stars 90 forks source link

Add support for swift concurrency #185

Closed BrentMifsud closed 2 months ago

BrentMifsud commented 10 months ago

With Swift 6 on the horizon, this library is going become quite painful to use.

Already today I am facing tons of actor isolation related compiler errors.

Are there any plans to address this?

for example:

image

edys commented 7 months ago

Until this is solved, a work around is to mark the init as nonisolated.

This should be ok for viewmodel as you would not expect to do anything that would require mainactor and if you did you could always create a task to run on the main actor.

The rest of the method on the viewmodel will still be protected by the main actor and called form SwiftUi view, which automatically run the body function in main actor isolation.

majie776 commented 7 months ago

这是来自QQ邮箱的自动回复邮件。   邮件已收到

BrentMifsud commented 5 months ago

Until this is solved, a work around is to mark the init as nonisolated.

This should be ok for viewmodel as you would not expect to do anything that would require mainactor and if you did you could always create a task to run on the main actor.

The rest of the method on the viewmodel will still be protected by the main actor and called form SwiftUi view, which automatically run the body function in main actor isolation.

This wouldn't work if you were working with an observable object for example.

You might want to compute the initial values of your published properties in the init which wouldn't be possible to do in a nonisolated context.

brianwang9100 commented 2 months ago

Cleanse is now deprecated. Please read the deprecation notice on the README for next steps. Thank you!