title: How do closures in Swift capture variables under the hood?
body: <p>I am trying out to figure out how does capturing in Swift closures work.</p>
  
  <p>Let's assume the following code example</p>
  
  <pre><code>class Worker {
      let block: () -&gt; Void
      let id: String
  
      init(id: String, block: @escaping  () -&gt; Void) {
          self.id = id
          self.block = block
      }
  }
  
  var worker: Worker!
  
  worker = Worker(id: "1", block: { _ in
      print(worker.id)
  })
  </code></pre>
  
  <p>At the moment the closure is being created, the worker variable is still nil. However, the closure will successfully capture the worker variable. </p>
  
  <p>How does that work? How does the closure keep a strong reference to a variable that still not being initialized? </p>