According to the Apple Developer Documentation Diagnosing Memory, Thread, and Crash Issues Early, in the "Detect Improper UI Updates on Background Threads" section, the libMainThreadChecker.dylib can be injected at runtime to an application in order to use the Main Thread Checker tool. How would one go about injecting this dylib before (if possible) or during runtime without using the diagnostic setting in Xcode? I've tried injecting using the osxinj and yololib projects on GitHub with no luck.
There's a number of ways you can do this: the easiest is probably setting the DYLD_INSERT_LIBRARIES
environment variable to /Applications/Xcode.app/Contents/Developer/usr/lib/libMainThreadChecker.dylib
. (You can do this from the "Arguments" tab of the Schemes editor.)
Another way would be to dynamically load it in code. Just put something like dlopen("/Applications/Xcode.app/Contents/Developer/usr/lib/libMainThreadChecker.dylib", RTLD_LAZY)
early in your app's startup path.
You could also directly link against the library, but that would hardcode the library into your app, which I would not really recommend for something used largely for debugging.
Click on your project name beside the Stop button -> Edit scheme. Under Diagnostics there's an option to enable/disable it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With