3

If a class is on @MainActor:

@MainActor class MyClass : NSObject
{
}

does this put all its extensions on @MainActor as well?

extension MyClass
{
}
meaning-matters
  • 21,929
  • 10
  • 82
  • 142

1 Answers1

6

Yes. As SE-0316 - Global actors says:

A type declared with a global actor attribute propagates the attribute to all methods, properties, subscripts, and extensions of the type by default.

Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • I was expecting this, but wasn't 100% sure. Thanks for the reference; I'm going to read through. Looks more thorough than TSPL. – meaning-matters Jan 31 '23 at 20:29
  • 2
    Yeah, [The Swift Programming Language](https://docs.swift.org/swift-book/LanguageGuide/Concurrency.html) is an accessible introduction to the concepts, but the [Swift Evolution Proposals](https://github.com/apple/swift-evolution/tree/main/proposals) tend to outline a few more implementation and design considerations. – Rob Jan 31 '23 at 21:16