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.2k times
1 Answers
152
Like this: [NSThread isMainThread]
omz
- 52,865
- 5
- 126
- 139
Noah Witherspoon
- 56,657
- 16
- 129
- 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