title: Swift Retain Cycles and Closures
body: <p>I have tried to do a lot of research on understanding retain cycles.  I can't seem to find anything on my examples though.  I do know that if i set a property to a closure then a retain cycle happens and need to use weak or unowned.  But i have 2 examples that I would like to know if they are done correctly: Thanks in advance, I have tried to see if they are on stackoverflow already but couldn't find anything.</p>
  
  <p><strong>Simple animations</strong></p>
  
  <pre><code>UIView.transitionWithView(self, duration: 5, options: .TransitionCrossDissolve, animations:    { [weak self] in
      self?.setNeedsDisplay()
      return
  }, completion: nil)
  </code></pre>
  
  <p><strong>Animations with an array</strong></p>
  
  <pre><code>for imageView in self.townImages {
      UIView.transitionWithView(imageView, duration: 0.3, options: .TransitionCrossDissolve, animations: { () -&gt; Void in
          imageView.image = UIImage(named: self.getImages()[count++])
      }, completion: nil)
  }
  </code></pre>
  
  <p>In both of these examples <code>self</code> is a subclass of <code>UIView</code>. I would just like to know that I am doing it correctly or if I should be using the imageView as weak reference too. Thanks.</p>