【发布时间】:2015-07-02 14:50:53
【问题描述】:
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
}
}
我对为什么需要使用 [unowned self] 感到有些困惑。根据this answer,我应该只使用 [unowned self] 如果 我不关心调用闭包时 self 仍然存在。但我从来不明白为什么会这样。为什么我不关心 self 是否在身边?当调用闭包时,我希望 self 存在——这就是我在那里编写代码的原因。
animations 闭包中是否需要 unowned self?
【问题讨论】:
标签: ios swift memory-management