Is it the right way using `[weak self]` in swift closure?
问题 I always using [weak self] in swift closure to prevent reference cycle. Here is the code below, is it the correct way? someTask(completion: {[weak self] (result) in if self == nil { return } //is it safe when reach here? self!.xxx = yyy self!.doLongTermWork() self!.finish() //will crash when self is nil? }) Weak self does not keep a strong hold on the instance. So when self.doLongTermWork() , will self be set to nil again somewhere else? 回答1: Your pattern has race condition. If self was