简体   繁体   中英

swift defer statement doesn't break point but does print

I put a defer inside a do, like so

do {
    defer {                     
        self.captureSession?.commitConfiguration()
        print("commitConfiguration")
    }

    self.captureSession?.beginConfiguration() 
    // try a bunch AV session setup calls
    ...
}
catch {
    // error
}

I tried to put a break point to ensure the defer block is stepped into at the end. To my surprise, it didn't. I checked documentation, ran the app, nothing is seemingly wrong. So I put a print statement. Lo and behold, it did print it, showing it probably did execute even though debug breakpoint never got activated.

Anyone observed this in Xcode 10.1 High Sierra ?

Yes, I noticed exactly the same thing. If memory serves it was at work using Xcode 9.4 and High Sierra. The defer fires, but the breakpoint doesn't break.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM