title: Swift: how to set function type value to optional variable?
body: <p>I want to use function as a completion for another function, when it's needed. But I have a trouble that best described with code:</p>
  
  <pre><code>...{
     var myCompletion : (() -&gt; Void)? = nil
     if condition {
         myCompletion = myCompletionFunction() // &lt;==========problem here
     }
     someMethodThatCouldHaveCompletion(myCompletion)
     ...
  }
  
  func someMethodThatCouldHaveCompletion(completion: (() -&gt; Void)?){
  ...
  }
  
  func myCompletionFunction() {
  ...
  }
  </code></pre>
  
  <p>I have an error: <code>Cannot assign a value of type '()' to a value of type '(()-&gt;Void)?'</code></p>
  
  <p>I tried to add <code>as! (() -&gt; Void)?</code> after setting function to myCompletion variable, but receive another error <code>Cannot downcast from '()' to a more optional type '(()-&gt;Void)?'</code></p>
  
  <p>So, is there a way to solve it? I have a sense that I miss something with <code>completion: (() -&gt; Void)?</code> type. </p>