Defer block is not executed

后端 未结 2 1425
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-18 15:34

I have the following swift code executing in playground:

func A() {
    print ("Hello")
    guard 1 == 2 else {
        return
    }
    defer {
            


        
2条回答
  •  时光取名叫无心
    2021-01-18 16:01

    Put the defer block before the scope is exited:

    func A() {
        print ("Hello")
        defer {
            print ("World")
        }
        guard 1 == 2 else {
            return
        }
    }
    
    A()
    

提交回复
热议问题