title: How should you handle closure arguments for UIAlertAction
body: <p>I have been trying to create a <code>UIAlertAtion</code> which also has a handler. I read the answers from <a href="https://stackoverflow.com/questions/24190277/writing-handler-for-uialertaction">this</a> question and know how to do it.</p>
  
  <p>My question is only about the closure portion of it. </p>
  
  <p><strong>1)</strong> I know I can write : <code>{alert in println("Foo")}</code> Or <code>{_ in println("Foo")}</code> but I <strong>can't</strong> write <code>{println("Foo")}</code>. In the comments <a href="https://stackoverflow.com/a/24190415/5175709">here</a> it is explained because <em>you need to handle the argument action</em>. </p>
  
  <p>Does this mean that since the handler is of type <code>(UIAlertAction) -&gt; Void)?</code> I must always capture the passed alertAction?</p>
  
  <hr>
  
  <p><strong>2)</strong>
  I also read <a href="https://stackoverflow.com/a/29054414/5175709">this</a> and the answer is basically saying you can pass in a function as your argument, but the function should take something of type <code>UIAlertAction -&gt; Void</code>, which I wrote :</p>
  
  <pre><code>private func anything(action : UIAlertAction) {
      print("hello")
  }
  </code></pre>
  
  <p>and then wrote my alertaction as such:</p>
  
  <pre><code>let anotherAction = UIAlertAction(title: "hi", style: UIAlertActionStyle.Default,
   handler: anything(action)) // error: Use of unresolved identifier 'action'
  </code></pre>
  
  <p>confused why I get that error</p>
  
  <hr>
  
  <p><strong>3)</strong>
  In the comments it also said: <em>But in addition to that you don't have to write UIAlertActionStyle.Default in swift. .Default works, too</em></p>
  
  <p>I tried writing not using the style so it would be defaulted to <code>.Default</code></p>
  
  <pre><code>let sendLogAction = UIAlertAction(title: "Log") { action in print("goodbye")}
  </code></pre>
  
  <p>But then I get the following error: </p>
  
  <blockquote>
    <p>'(title: String, (_) -> ())' (aka '(title: String, _ -> ())') is not
    convertible to '(title: String?, style: UIAlertActionStyle, handler:
    ((UIAlertAction) -> Void)?)' (aka '(title: Optional, style:
    UIAlertActionStyle, handler: Optional ()>)'), tuples
    have a different number of elements</p>
  </blockquote>
  
  <hr>
  
  <p><strong>4)</strong>
  Also reading <a href="https://stackoverflow.com/a/24022696/5175709">this</a> answer. I don't understand why we need to pass in <code>alert</code> it makes no sense. It's not like we don't know what are alert's type is...haven't we already defined its type?!! Can anyone explain where passing the action itself would be useful in general, I mean what could we do with it?</p>
  
  <hr>
  
  <p>I know this is wrote as 4 questions but I think it's really just a foundational question. I have extensively <a href="https://www.weheartswift.com/closures/" rel="nofollow noreferrer">read</a>, used closures/completion handlers in a project I'm working and played in playground but still I'm confused. </p>