swift - Should I use weak self inside a computed property's closure? -
i confused using self
inside closure.
when should declare [weak self]
? obvious case understand is
class foo{ var closure: ( void -> void )? var x = 0 func dosomething(){ closure = { [weak self] in if let x = self?.x{ println(x) } } } }
however, if want create computed property bar
, has closure, , captures self inside. this,
extension foo{ var bar: bar{ let bar = bar() bar.completionhandler = { println(self.x) } return bar } }
should use [weak self]
inside closure?
Comments
Post a Comment