【发布时间】:2015-12-07 15:58:18
【问题描述】:
如果您需要在闭包内引用self,最好将其作为weak 或unowned 传递以防止保留循环。
如果我直接传递属于self的函数,会不会导致retain循环?或者它是否需要嵌套在一个闭包中来弱化自我?
直接通过
UIView.animateWithDuration(0.3,
delay: 0.0,
usingSpringWithDamping: 0.7,
initialSpringVelocity: 0.1,
options: .CurveEaseOut,
animations: self.view.layoutIfNeeded, // does this cause retain cycle?
completion: nil)
包装在一个闭包中
UIView.animateWithDuration(0.3,
delay: 0.0,
usingSpringWithDamping: 0.7,
initialSpringVelocity: 0.1,
options: .CurveEaseOut,
animations: { [unowned self] in
self.view.layoutIfNeeded()
},
completion: nil)
【问题讨论】:
标签: swift memory-management functional-programming swift2 retain-cycle