Is self captured within a nested function

前端 未结 3 1797
攒了一身酷
攒了一身酷 2021-02-03 23:16

With closures I usually append [weak self] onto my capture list and then do a null check on self:

func myInstanceMethod()
{
    let myClosure =
            


        
3条回答
  •  鱼传尺愫
    2021-02-04 00:13

    Unfortunately, only Closures have "Capture List" feature like [weak self]. For nested functions, You have to use normal weak or unowned variables.

    func myInstanceMethod() {
        weak var _self = self
        func nestedFunction(result : Bool) {
            _self?.anotherInstanceMethod()
        }
    
        functionExpectingClosure(nestedFunction)
    }
    

提交回复
热议问题