Hi everyone ![]()
First, thanks to Konrad for the initial explanation and for suggesting that I move this discussion to the public forums so others can benefit from it as well. His explanation helped me understand that these changes are mainly about controlling where async code executes and why that matters for runtime performance, even when using AI coding agents.
I'm relatively new to Swift and currently learning more about Swift concurrency. I've been exploring two proposals introduced in Swift 6.2,
-
SE-0466: Control default actor isolation inference.
-
SE-0461:
nonisolated(nonsending)and@concurrent.
I understand the basic concepts, but I'm trying to understand how they work together in real applications.
1. How do default actor isolation and async execution work together?
SE-0466 allows a project or module to configure MainActor as its default isolation.
For example,
@MainActor
class UserViewModel {
var username = ""
func updateUsername(_ name: String) {
username = name
}
}
If a project uses MainActor as its default isolation, how should we handle functions that perform background work? Does explicitly using nonisolated provide a way to separate that work from MainActor, and how does this interact with async functions?
2. When should we use nonisolated(nonsending) and @concurrent?
SE-0461 introduces different ways to control where nonisolated async functions execute.
nonisolated(nonsending)
func fetchUserData() async {
// Async work using the caller's actor
}
@concurrent
func processUserData() async {
// Work on the generic executor
}
Imagine a SwiftUI application that fetches data from an API, processes a large amount of data, and then updates the UI... Which execution model would be appropriate for each operation? Would @concurrent be the right choice for CPU-intensive processing, and when would a custom actor be more appropriate?
I'd also like to understand how non Sendable values are handled when passing data between these isolation contexts.
3. How do actors, executors and threads relate to each other?
This is probably one of the areas I'm finding most difficult to understand....
I understand that actors provide isolation and executors determine where jobs are scheduled, but I'm still trying to connect these concepts.
For example does switching to the generic executor necessarily mean switching to another thread? How does Swift's cooperative thread pool schedule concurrent tasks, particularly when some tasks perform CPU intensive work?
4. Learning Swift in the AI era
One final question, following my earlier conversation with Konrad.
Konrad mentioned that even with AI agents, it's still important to understand what's happening inside a system rather than relying entirely on generated code. I found that perspective interesting, especially as someone who is still relatively new to Swift.
With AI coding agents becoming increasingly capable of generating Swift code, how deeply should beginners understand concepts like concurrency, memory management and system behaviour?Would you recommend learning these fundamentals in depth before building larger applications, or focusing on building projects first and learning the deeper concepts along the way?
I'd be interested to hear how experienced Swift developers approach this, particularly in today's AI assisted development environment.
I'm still learning, so please feel free to correct anything I've misunderstood.
Thanks again to @ktoso for the initial guidance and thanks to everyone who takes the time to share their knowledge :)