Firebase's callback functions are executed in the main thread. How do I schedule work to perform on the background thread with Swift?
Asked
Active
Viewed 532 times
0
-
Are you using firebase async methods? Would you give an example code how are you using those? – Shahin Oct 26 '20 at 14:32
-
There's a perfect answer already provided; code in Firebase closures do *not* execute on the main thread; network operations on a background thread, UI calls are on the main thread. But, what do you mean by 'work'? The question is vague without some use case. Can you elaborate a bit by updating your question and describing (with code) what you're trying to do? We can probably come up with a more concise answer if we have more info. – Jay Oct 26 '20 at 20:31
1 Answers
2
Firebase already performs all its network and disk I/O off the main thread, and only then calls your code on the main thread so that you can update the UI.
If you want to then schedule your code to run on another thread, that has nothing to do with Firebase anymore. I recommend looking at some of these search results, like this one on dispatch queues: How to use background thread in swift?

Frank van Puffelen
- 565,676
- 79
- 828
- 807