Main Thread Checker in XCode
I’ve been using Main thread checker from XCode 9, And It feels amazing if some tool is there to point out your mistakes (instead of a human being😅).
What It does ?
Basically It will verify your code and will point out code which should be in main thread instead of background. It can evaluate code which is written in Swift and C language.
How to enable ?
- Edit scheme.
- Select run scheme.
- Select the Diagnostics tab.
- Check the Main Thread Checker Check Box.
- Click on small arrow written besides MTC text (Optional).
On click on arrow message besides main thread checker will add breakpoint for the project for debugging.
How it works ?
During runtime it will check if all UI and other code which should be run in main thread is working or not, incase it is not working it will pause at the line of code which should be put in main thread along with appropriate warning message.
If main thread debugger break point is not added and one wish to identify issues without that then you can get a look at the list of all the main thread issues in runtime error messages.
Why to use ?
Threading is a very powerful thing, if one knows the beauty of it and can use it in correct way just like boolean. Threading can lead to some major problems. So it’s better to take precautions by using such facility provided by apple. To get in depth of this developers can use profiler too.
There are lot of other features which developer can leverage for sanity checking of code(can view in the below screenshots), like Thread sanitizer and other breakpoints provided by XCode..