Search code examples
swiftxcodebreakpoints

Swift Xcode 11 breakpoints for conditionals do not work


I am trying to add a Symbolic Breakpoint in XCode to check for UI engine modifications on the background thread.

What I am doing is the following:

enter image description here

However, the error message I am getting back is always:

Stopped due to an error evaluating condition of breakpoint 5.1: "!Thread.isMainThread"
Couldn't parse conditional expression:
error: use of undeclared identifier 'Thread'

UI Engine must be modified on main thread.

I do not understand why the breakpoint condition cannot evaluate my condition. Can someone explain what I may be doing wrong here? I have tried putting that in Obj-c as well, to no luck.

EDIT: Obj-C version, here: !(BOOL)[NSThread isMainThread]

EDIT 2: Xcode version Version 11.3 (11C29)

EDIT 3: Ok, so, closing XCode and reopening has gotten the Obj-C version "working" they pause on a breakpoint for something like, 4-5 minutes each time. This effectively makes these breakpoints unusable. Not sure how to resolve this.


Solution

  • I was able to get your original symbolic breakpoint working as expected by writing the condition as

    (BOOL)[NSThread isMainThread] == NO
    

    I suspect there's a better way, and comparing a BOOL directly to NO is very bad style, but at least it got me past the "doesn't work" stage to the "does work" stage.