Runtime warnings are super useful, from the main thread checker to the SwiftUI runtime warnings that have been introduced the past few years.
Unfortunately, creating these runtime warnings is closed, which means it’s not possible for libraries to notify users of issues in a nice way.
Instead, we’re stuck using cruder tools:
Swift.assertion,precondition, and friends, which crash the application, even if the runtime issue is safe enough to ignore and execution can resume.SIGTRAPto enter a breakpoint, which only raises if it detects that a debugger is attached, or crashes otherwise.SIGTRAPalso enters the debugger at a stack frame different from where the signal was raised, making it more difficult to track down the relevant frame.
Ideally Xcode would provide an API for issuing a purple runtime warning and the ability to provide a context (like #file and #line), so that a library can associate the warning with the appropriate call site.
Just found your workaround for this little
runtimeWarngemThank you so much for all of these amazing tips.