Replacing printf debugging with a real debugger

Hi. Is there a way to check what would happen if I were to put a print(whatever) at the point I have my breakpoint at, without recompiling the app?

For Xcode, I’d suggest WWDC 2018: Advanced Debugging with Xcode and LLDB

1 Like

I didn't watch the whole hour long video, but it seems they are using po and expression commands to interact with the code. They are almost what I want, but unfortunately they don't behave like the real swift code, for example if your program is

func f<T>(_ foo: T) {
    print(foo != nil)
}
let x: Int? = nil
f(x)

then expression print(foo != nil) will give you false, but the print in the code will give you true

Did I miss some trick from the video, or is there no way to replace having to recompile your code?

Most definitely a bug, worthy of bug reports.

1 Like

I filed one a month ago but apparently debugger is working as expected
https://bugs.swift.org/browse/SR-12397

Responded to you bug report. Also see for a workaround Generic function that requires the generic type to be non-optional - #11 by ylorn

1 Like

Thanks!

Your workaround doesn't work for me, because it doesn't make me any more confident at using the debugger. I don't want to make two versions of EVERY generic function in ALL my programs. Also, the problem exists even if you don't use nil, even if you don't use Optional, even if you don't do any casting. I put an example in the bug report

I agree with @cukr, it'd be very confusing if the debugger use the dynamic type, instead of the static one for any resolutions like this.