Skip to content

Instantly share code, notes, and snippets.

@stephencelis
Last active September 20, 2024 07:38
Show Gist options
  • Select an option

  • Save stephencelis/a8d06383ed6ccde3e5ef5d1b3ad52bbc to your computer and use it in GitHub Desktop.

Select an option

Save stephencelis/a8d06383ed6ccde3e5ef5d1b3ad52bbc to your computer and use it in GitHub Desktop.

Library users should be able to create runtime warnings

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.
  • SIGTRAP to enter a breakpoint, which only raises if it detects that a debugger is attached, or crashes otherwise. SIGTRAP also 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.

@kdeda
Copy link
Copy Markdown

kdeda commented Dec 14, 2023

Just found your workaround for this little runtimeWarn gem
Thank you so much for all of these amazing tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment