Elektrine lite

← Feed

@rhysmorgan@mastodon.social

Post #959402

2026-04-06 18:16 UTC

Sharing this repo to demonstrate something I consider to be truly incredible in modern Swift with Approachable Concurrency. Your View Models no longer *need* to be MainActor-isolated just because your SwiftUI View* reads or mutates a property on it. Your View Model tests can be totally nonisolated, and not have to mark them @.MainActor + experience MainActor-contention. Thank you @mattiem for showing me this is possible! https://github.com/rhysm94/NonIsolatedViewModels *and presumably UIView/UIViewController

Replies (2)

  • @rhysmorgan @mattiem Hi Rhys, Thank you for sharing. This is a real eye opener. Can you elaborate on how this is working? Why is there no race condition when mutating the person from a concurrent task? Sincerely, Morten

    Open ##1839160

  • @akbashev@mastodon.social 2026-04-07 07:56

    @rhysmorgan @mattiem isn’t it a problem for testing, actually? Cause with NonisolatedNonsendingByDefault enabled you’ll have two behaviours effectively—ViewModel for view will run on main actor isolation, and on whatever isolation for tests. Plus tests are parallel, main actor isolation helps here.

    Open ##1839164