title: Swift optional escaping closure
body: <p><a href="https://i.stack.imgur.com/5wrgI.png" rel="noreferrer"><img src="https://i.stack.imgur.com/5wrgI.png" alt="enter image description here"></a></p>
  
  <p>Compiler error <code>Closure use of non-escaping parameter 'completion' may allow it to escape</code>, Which make sense because it will be called after the function return.</p>
  
  <pre><code>func sync(completion:(()-&gt;())) {
      self.remoteConfig.fetch(withExpirationDuration: TimeInterval(expirationDuration)) { (status, error) -&gt; Void in
          completion()
      }
  }
  </code></pre>
  
  <hr>
  
  <p>But if I make closure optional then no compiler error, Why is that? closure can still be called after the function returns. </p>
  
  <pre><code>func sync(completion:(()-&gt;())?) {
      self.remoteConfig.fetch(withExpirationDuration: TimeInterval(expirationDuration)) { (status, error) -&gt; Void in
          completion?()
      }
  }
  </code></pre>