Is self captured within a nested function

前端 未结 3 1863
攒了一身酷
攒了一身酷 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-03 23:54

    Does not seem to be the case anymore. This is valid in swift 4.1:

    class Foo {
        var increment = 0
        func bar() {
            func method1() {
                DispatchQueue.main.async(execute: {
                    method2()
                })
            }
    
            func method2() {
                otherMethod()
                increment += 1
            }
            method1()
        }
    
        func otherMethod() {
    
        }
    }
    

    The question remains: How is self captured ?

提交回复
热议问题