title: What determines whether a Swift 5.5 Task initializer runs on the main thread?
body: <p>This is sort of a follow-up to my earlier <a href="https://stackoverflow.com/questions/67913756/asyncdetached-falling-back-into-main-thread-after-mainactor-call">asyncDetached falling back into main thread after MainActor call</a>.</p>
  <p>Here's the complete code of an iOS view controller:</p>
  <pre><code>import UIKit
  
  func test1() {
      print(&quot;test1&quot;, Thread.isMainThread) // true
      Task {
          print(&quot;test1 task&quot;, Thread.isMainThread) // false
      }
  }
  class ViewController: UIViewController {
      override func viewDidLoad() {
          super.viewDidLoad()
          test1()
          test2()
      }
  
      func test2() {
          print(&quot;test2&quot;, Thread.isMainThread) // true
          Task {
              print(&quot;test2 task&quot;, Thread.isMainThread) // true
          }
      }
  }
  </code></pre>
  <p>The two functions <code>test1</code> and <code>test2</code> are identical, and are being called from the very same place. Yet one of them runs its Task initializer <code>operation:</code> function on a background thread, and the other runs on the main thread.</p>
  <p>What determines this? I can only think it has to do with where the method is declared. But <em>what</em> does it have to do with where the method is declared?</p>