Swift 闭包中self? 的由来

xiaoxiao2021-02-27  139

class UIViewSpringAnimator: SwipeAnimator {

    

    // 动画完成的闭包

    var completion:((Bool) ->Void)?

        

    func addCompletion(completion:@escaping (Bool) ->Void) {

        self.completion = { [weakself] finished in

            

            guardself?.isRunning ==true else {return }

            

            self?.isRunning =false

            self?.animations =nil

            self?.completion =nil

            

            completion(finished)

        }

    }

}

[weak self] 的作用
转载请注明原文地址: https://www.6miu.com/read-14771.html

最新回复(0)