How to determine if the current thread inside a method is a main thread, or just a thread that is asynchronous and created? Does the ID tell me?
Asked
Active
Viewed 2.4k times
1 Answers
154
Like this: [NSThread isMainThread]

omz
- 53,243
- 5
- 129
- 141

Noah Witherspoon
- 57,021
- 16
- 130
- 131
-
Alternative way: -(BOOL)IsMainThread { return dispatch_get_main_queue() == dispatch_get_current_queue(); } – Durai Amuthan.H Oct 21 '13 at 09:13
-
5`dispatch_get_current_queue()` is deprecated as of iOS 6. – Noah Witherspoon Oct 21 '13 at 14:33
-
4**For Swift 3** `if Thread.isMainThread { print("Main Thread") }` – dimohamdy Dec 04 '16 at 15:35