title: Optional closures in Swift protocols
body: <p>Let's say that I have a protocol and a class conforming to this protocol. </p>
  
  <pre><code>protocol Foo {
      func task(success: (() -&gt; Void)?)
  }
  
  class Bar: Foo {
      func task(success: (() -&gt; Void)?) {
          //DO STUFF
      }
  }
  </code></pre>
  
  <p>Success closure is an optional, because not every call will require it. For example, this is a common situation when calling such function from an unit test, because we want to fulfill expectation in the success closure, while in a regular call success closure is not needed for some reason. </p>
  
  <p>Since functions defined in protocols cannot have default values for their parameters, for each call to task on object conforming to <code>Foo</code>, We have to call it with the closure or pass explicitly nil as the closure value:</p>
  
  <pre><code>var obj: Foo
  obj = Bar()
  obj.task(nil) //CLOSURE VALUE SET TO nil
  obj.task() {} //EMPTY CLOSURE
  obj.task() //NOT ALLOWED
  </code></pre>
  
  <p>What is a recommended method to implement such a structure? Do we need to pass empty closures every time, or calling functions with closure value set to nil, or is there another way to deal with it?</p>