Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 406
kawingkelvin Avatar asked Oct 16 '25 13:10

kawingkelvin


1 Answers

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.

like image 177
Duncan C Avatar answered Oct 19 '25 03:10

Duncan C



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!