# @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.