title: When to use closures in swift?
body: <p>I am been to ios development for few months and eager to implement new things in my programming pattern.</p>
  
  <p>Now i am learning closures and knew little things about its syntax,knew it can be used instead of delegate for callbacks. As well as implemented it in some UIViewAnimation and for sorting.</p>
  
  <p>But really i want to know its uses apart from that.i.e where should we use closures in our basic programming. Like we use delegate when we want to send information from child to parent.. So any explanation or brief example on its actual which can be used in our day to day swift programming would be helpful?</p>
  
  <p>Can anyone tell me how these closure actually computes the value </p>
  
  <pre><code>reversed = sorted(names, { (s1: String, s2: String) -&gt; Bool in return s1 &gt; s2 } )
  </code></pre>
  
  <p>In these example there is names and closure as an argument to a method..but how does this actually computes ?</p>
  
  <p>Can you please explain how these works when passing closures in this animation code :</p>
  
  <pre><code>UIView.animateWithDuration(duration: NSTimeInterval, 
      animations: (() -&gt; Void)?, 
      completion: ((Bool) -&gt; Void)?)
  </code></pre>
  
  <p>I really want to know about the flow?</p>