2
override func viewDidLoad() {
    super.viewDidLoad()
    self.view.backgroundColor = UIColor(netHex: 0xfc3158)
    fadeBackground()
    NSTimer.scheduledTimerWithTimeInterval(self.fadeTime, target: self, selector: Selector("fadeBackground"), userInfo: nil, repeats: true)
}

func fadeBackground(){
    UIView.animateWithDuration(self.fadeTime, delay: 0, options: UIViewAnimationOptions.AllowUserInteraction, animations: {
        var randomIndex = Int(arc4random_uniform(UInt32(CONSTANTS.MainColorScheme.count)))
        self.view.backgroundColor = CONSTANTS.MainColorScheme[randomIndex]
    }) { (stuff Bool) -> Void in
    }
}

I'm a little confused about why I need to use [unowned self]. According to this answer, I should only use [unowned self] if I don't care that self is still around when the closure is called. But I never see why that would ever be the case. Why would I not care if self is around? I want self to be around when the closure is called -- that's why I wrote the code there.

Do I need unowned self in the animations closure?

Community
  • 1
  • 1
Jess
  • 71
  • 5

1 Answers1

3

In this case you don't need to use capture list, because both closures are UIView and not retained by self. The retain cycle is not created in your example.

Kirsteins
  • 27,065
  • 8
  • 76
  • 78