So as a general rule, we need to conform View Models to MainActor for the sake of UI updates happening on the MainActor, but that causes contention on the MainActor when testing.

I wonder if there’s a way to default isolate, maybe via a parameter, to the MainActor, but for the sake of testing to allow it to be effectively nonisolated? #swiftlang #iosdev

@rhysmorgan I always make view models MainActor because they wind up having lots of things that rely on main actor (such as observing other main actor types, notifications, Combine, etc), but if you truly have view models that have no such dependencies, I wouldn’t think marking them main actor would be needed. In Swift 6, non-Sendable types just have to stay where they’re created, so if they’re created on the main actor, they should be fine there.
@rhysmorgan for me, non-Sendable types rarely work because I always bump into something that doesn’t quite work (like an unstructured Task), but if you’ve built a Swift 6 structured concurrency system without all those sharp edges, I’d expect non-Sendable types to be the right answer.
@cocoaphony Yes, I don’t have a proper Swift 6 structured concurrency system in the codebase I work in daily haha.
Trying to understand best practices around non-Sendable types - especially for View Models, as we move more features to Swift 6.
@rhysmorgan My experience in larger projects is that running tests in parallel is dicey and I avoid it. Getting everything perfect is too hard. There can't be any singletons in the system. Even basic stuff like NotificationCenter bite you unless you're really careful. I prefer to just accept that singletons (sharedInstance) are good actually, and make them testable. But the trade-off is that I don't even try to make them parallel on the same simulator (I shard to multiple simulators sometimes).