title: How to pass a function as an optional parameter Swift
body: <p>New to Swift and I am currently getting around passing a function as an optional parameter in the following way:</p>
  
  <pre><code>import Foundation 
  
  func foo()
  {
      print("Foo")
  }
  
  func bar()
  {
      print("Bar")
  }
  
  func dummy()
  {
      return
  }
  
  func myFunc()
  {
      myFunc(callBack: dummy())
  }
  
  func myFunc(callBack: (Void))
  {
      foo()
      callBack
  }
  
  myFunc()
  myFunc(callBack: bar())
  </code></pre>
  
  <p>i.e. exploiting polymorphism</p>
  
  <p>This seems like an inelegant way to do this, is there a better way,</p>
  
  <p>Thanks,
  Tom</p>
  
  <p>edit:</p>
  
  <p>I am aware I could shorten this by doing:</p>
  
  <pre><code>import Foundation 
  
  func foo()
  {
      print("Foo")
  }
  
  func bar()
  {
      print("Bar")
  }
  
  func dummy()
  {
      return
  }
  
  func myFunc(callBack: (Void) = dummy())
  {
      foo()
      callBack
  }
  
  myFunc()
  myFunc(callBack: bar())
  </code></pre>
  
  <p>But I would still say this is an inelegant solution</p>