Can I cause Xcode's debugger to break programmatically? Can I cause Xcode's debugger to break programmatically? swift swift

Can I cause Xcode's debugger to break programmatically?


For Swift, raise(SIGINT) works for me.

I have this function:

func fail(desc: String) {  #if DEBUG    print("assertFail:\(desc)")    raise(SIGINT)  #endif}

For DEBUG macro setup see here: In absence of preprocessor macros, is there a way to define practical scheme specific flags at project level in Xcode project


Putting asm("svc 0") in your code will stop your running application if debugging through xcode. See: https://stackoverflow.com/a/34078247/215400


I'm not 100% positive there isn't a built in one - but you can create what you want yourself using Symbolic Breakpoints in the XCode UI.

1) Create a new class to represent your Debugger Break.

@interface MYDebuggerBreak : NSObject+(void)fireUpDebugger;@end@implementation MyDebuggerBreak+(void)fireUpDebugger {    // Do Nothing}@end

2) Add a Symbolic Breakpoint to a method on that Class

[MYDebuggerBreak fireUpDebugger]

This is a bit roundabout, you could also put a breakpoint directly into the line "fireUpDebugger" since you control the code. Symbolic Breakpoints are more useful if you want to stop on a method call for something you don't control.