# dispatchqueue

Published articles for dispatchqueue.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## @MainActor in Swift explained with code examples

DevFeed: [@MainActor in Swift explained with code examples](<https://devfeed.tech/articles/mainactor-in-swift-explained-with-code-examples-11486.md>)

Original publisher: [Read original article](<https://www.avanderlee.com/swift/mainactor-dispatch-main-thread/>)

Author: Antoine van der Lee

Published: 2026-08-02T12:04:47Z

Content type: tutorial

Language: en

Sources: [SwiftLee](<https://devfeed.tech/sources/swiftlee.md>)

Topics: [Swift](<https://devfeed.tech/topics/swift.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [Code](<https://devfeed.tech/topics/code.md>), [Xcode](<https://devfeed.tech/topics/xcode.md>)

Tags: [article](<https://devfeed.tech/tags/article.md>), [code](<https://devfeed.tech/tags/code.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [dispatchqueue](<https://devfeed.tech/tags/dispatchqueue.md>), [examples](<https://devfeed.tech/tags/examples.md>), [guide](<https://devfeed.tech/tags/guide.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [main-thread](<https://devfeed.tech/tags/main-thread.md>), [swift](<https://devfeed.tech/tags/swift.md>), [thread](<https://devfeed.tech/tags/thread.md>), [xcode](<https://devfeed.tech/tags/xcode.md>)

### AI overview

This tutorial explains how Swift's @MainActor global actor ensures that properties, methods, instances, and closures execute on the main thread. It also covers compiler-enforced main-thread execution, global actor isolation, nonisolated methods, and changes to default actor isolation in Swift 6.2 and Xcode 26.

### Source excerpt

@MainActor is a global actor that performs its tasks on the main thread. You can use it to dispatch to the main thread by marking properties, methods, instances, or closures with the attribute. Instead of manually dispatching using DispatchQueue.main.async, you let the compiler enforce main thread execution for you. If you're new to Actors in ... -> The post @MainActor in Swift explained with code examples appeared first on SwiftLee.

## How the Swift compiler knows that DispatchQueue.main implies @MainActor

DevFeed: [How the Swift compiler knows that DispatchQueue.main implies @MainActor](<https://devfeed.tech/articles/how-the-swift-compiler-knows-that-dispatchqueue-main-implies-mainactor-21724.md>)

Original publisher: [Read original article](<https://oleb.net/2024/dispatchqueue-mainactor/>)

Author: Ole Begemann

Published: 2024-02-29T18:54:47Z

Content type: article

Language: en

Sources: [Ole Begemann](<https://devfeed.tech/sources/ole-begemann.md>)

Topics: [Swift](<https://devfeed.tech/topics/swift.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [Xcode](<https://devfeed.tech/topics/xcode.md>)

Tags: [actor](<https://devfeed.tech/tags/actor.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [dispatchqueue](<https://devfeed.tech/tags/dispatchqueue.md>), [swift](<https://devfeed.tech/tags/swift.md>), [xcode](<https://devfeed.tech/tags/xcode.md>)

### AI overview

The article explains that Swift treats closures passed to exactly spelled DispatchQueue.main.async calls as @MainActor-isolated. It reports that this behavior comes from a coarse syntax-based check in the compiler's semantic analysis rather than an annotation on the method, and notes that equivalent expressions using aliases or variables do not receive the same inference.

### Source excerpt

You may have noticed that the Swift compiler automatically treats the closure of a DispatchQueue.main.async call as @MainActor. In other words, we can call a main-actor-isolated function in the closure: import Dispatch @MainActor func mainActorFunc() { } DispatchQueue.main.async { // The compiler lets us call this because // it knows we're on the main actor. mainActorFunc() } This behavior is welcome and very convenient, but it bugs me that it's so hidden. As far as I know it isn't documented, and neither Xcode nor any other editor/IDE I've used do a good job of showing me the actor context a function or closure will run in, even though the compiler has this information. I've written about a similar case before in Where View.task gets its main-actor isolation from, where Swift/Xcode hide essential information from the programmer by not showing certain attributes in declarations or the documentation. It's a syntax check So how is the magic behavior for DispatchQueue.main.async implemented? It can't be an attribute or other annotation on the closure parameter of the DispatchQueue.async method because the actual queue instance isn't known at that point. A bit of experimentation reveals that it is in fact a relatively coarse source-code-based check that singles out invocations on DispatchQueue.main, in exactly that spelling. For example, the following variations do produce warnings/errors (in Swift 5.10/6.0, respectively), even though they are just as safe as the previous code snippet. This is because we aren't using the "correct" DispatchQueue.main.async spelling: let queue = DispatchQueue.main queue.async { // Error: Call to main actor-isolated global function // 'mainActorFunc()' in a synchronous nonisolated context mainActorFunc() // ❌ } typealias DP = DispatchQueue DP.main.async { // Error: Call to main actor-isolated global function // 'mainActorFunc()' in a synchronous nonisolated context mainActorFunc() // ❌ } I found the place in the Swift compiler source code

## Perfect is the Enemy of the Good

DevFeed: [Perfect is the Enemy of the Good](<https://devfeed.tech/articles/perfect-is-the-enemy-of-the-good-22305.md>)

Original publisher: [Read original article](<https://www.thecodedself.com/Perfect-Is-The-Enemy-Of-The-Good/>)

Author: Keegan Rush

Published: 2018-11-13T00:00:00Z

Content type: opinion

Language: en

Sources: [The Coded Self](<https://devfeed.tech/sources/the-coded-self.md>)

Topics: [Development](<https://devfeed.tech/topics/development.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [reactive](<https://devfeed.tech/topics/reactive.md>), [Dependency injection](<https://devfeed.tech/topics/dependency-injection.md>), [Mocking](<https://devfeed.tech/topics/mocking.md>), [App](<https://devfeed.tech/topics/app.md>)

Tags: [architecture](<https://devfeed.tech/tags/architecture.md>), [architecture-pattern](<https://devfeed.tech/tags/architecture-pattern.md>), [async](<https://devfeed.tech/tags/async.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [dependency-injection](<https://devfeed.tech/tags/dependency-injection.md>), [development](<https://devfeed.tech/tags/development.md>), [dispatchqueue](<https://devfeed.tech/tags/dispatchqueue.md>), [mocking](<https://devfeed.tech/tags/mocking.md>), [programming](<https://devfeed.tech/tags/programming.md>), [queue](<https://devfeed.tech/tags/queue.md>), [reactive](<https://devfeed.tech/tags/reactive.md>), [reactive-programming](<https://devfeed.tech/tags/reactive-programming.md>)

### AI overview

The author reflects on a side project whose elaborate architecture and extensive tooling created hidden complexity, debugging difficulties, and development friction. The article examines the use of RxSwift, VIPER, Swinject, Cuckoo, and Flow Operations in an app and argues that architectural perfection can undermine practical progress.

### Source excerpt

How the Wrong Architecture Can Cripple Development A couple of years ago, I was working on a side project with a few friends. We thought that it would be the next big thing. We put our collective best efforts into it; I worked long, hard hours fleshing out the scaffolding of the perfect architecture. Little did I know that my effort would doom the project to join the abyss of failed projects as quickly as it had begun. We had the best tools Since this was The Next Big Thing™, we used everything at our disposal. RxSwift for reactive programming VIPER for our architecture pattern Swinject for dependency injection Cuckoo for mocking Flow Operations for managing navigation The Flow Operations were a particularly interesting concept, inspired by the Advanced NSOperations session from WWDC 2015. We used Flow Operations to manage navigation in the app. For instance, if you wanted to register a new user, you'd invoke a RegisterFlowOperation. A FlowOperation was a subclass of Operation: class FlowOperation: Operation The Operation class represents the code and data for a task of your choosing. It also handles concurrency and dependencies. So, our Flow Operations represented the task of flowing from one screen to another in an app. Operations can be dependent on each other - for instance, the EditProfileFlowOperation is dependent on the SignInFlowOperation. If you've already signed in, you can edit your profile, but if you haven't, then you'll be directed to sign in if you invoke the EditProfileFlowOperation. How does it work? There was a lot of hidden complexity in the Flow Operation system, and some trickiness that you wouldn't notice until you started using it. I'll briefly go over some of the code. You could sell products in this app we were building. This is how you'd start the Sell Flow: private func startSellFlow() { DispatchQueue.global().async { [navController = navController] in let flow = SellFlowOperation(navigationController: navController) flow.beginFlow() flow.