Detect access to UIKit from non-main-thread as a debugging feature

Originator:steipete
Number:rdar://27192338 Date Originated:06-Jul-2016 11:31 AM
Status:Open Resolved:
Product:iOS Product Version:9.3.2
Classification:Enhancement Reproducible:Always
 
Summary:
UIKit should have a debug mode where it can help detecting access to properties from background threads.
This can be done today via 3rd-party code, like my main thread guard which is very popular:
https://gist.github.com/steipete/5664345

Android has a StrictMode which detects that but goes way beyond:

>StrictMode is a developer tool which detects things you might be doing by accident and brings them to your attention so you can fix them.
>StrictMode is most commonly used to catch accidental disk or network access on the application's main thread, where UI operations are received and animations take place. Keeping disk and network operations off the main thread makes for much smoother, more responsive applications. By keeping your application's main thread responsive, you also prevent ANR dialogs from being shown to users.

https://developer.android.com/training/articles/perf-anr.html
https://developer.android.com/reference/android/os/StrictMode.html

Steps to Reproduce:
Access UIKit from background threads. Observe that things *might* just work, delayed. If you’re lucky. Or crash.

Expected Results:
Have a special mode (like Address Sanitizer) or something that can be called in code (like StrictMode) that can help us find such problems faster.

Actual Results:
Such helper does not exist.

Regression:
Never existed. But I bet Apple has something like that internally :)

Notes:
No sample needed - this is a conceptual question and I wrote this radar based on a recommendation by Typer Fox from the UIKit team.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!